2010-07-05 27 views
3

我有一个开发的应用程序,我只是试图使构建过程容易。父母的POM文件如下所示:如何部署一个特定的子项目与货物:开始使用maven

<parent> 
    <groupId>com.shc.obu.ca</groupId> 
    <artifactId>shcobuca-pom</artifactId> 
    <version>1.1.0</version> </parent> 

    <groupId>com.shc.obu.ca.osol</groupId> <artifactId>apps-pom</artifactId> <version>${currVersion}</version> <packaging>pom</packaging> <name>Outlet Apps</name> 

    <scm> 
    <connection>scm:svn:https://ushofsvpsvn2.intra.searshc.com/svn/outlet/outlet/trunk/apps</connection> 
    <developerConnection>scm:svn:https://ushofsvpsvn2.intra.searshc.com/svn/outlet/outlet/trunk/apps</developerConnection> </scm> 
    <profiles> 
    <profile> <id>www</id> 
     <activation> <activeByDefault>true</activeByDefault> </activation> 
     <modules> 
     <module>www</module> 
     <module>modules</module> 
     </modules> 
    </profile> 
    <profile> 
     <id>mts</id> 
     <activation> <activeByDefault>true</activeByDefault> </activation> 
     <modules> 
     <module>mts</module> 
     <module>modules</module> 
     </modules> 
    </profile> 
    <profile> <id>search</id> 
     <activation> <activeByDefault>true</activeByDefault> </activation> 
     <modules> 
     <module>modules</module> 
     <module>search</module> 
     </modules> 
    </profile> </profiles> 

    <repositories> 
    <repository> 
     <id>obu.ca.repo.release</id> 
     <snapshots><enabled>false</enabled></snapshots> 
     <url>http://maven.cal.intra.sears.com/release</url> 
    </repository> 
    <repository> 
     <id>obu.ca.repo.snapshot</id> 
     <releases><enabled>false</enabled></releases> 
     <snapshots> 
     <enabled>true</enabled> 
     <updatePolicy>interval:5</updatePolicy> 
     </snapshots> 
     <url>http://maven.cal.intra.sears.com/snapshot</url> 
    </repository> </repositories> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <env>trunk</env> 
    <currVersion>1.2.0</currVersion> </properties> </project> 

此文件显示它具有三个基本上独立的子项目的配置文件。我加入的货物插件如下文件:

<build> 
    <plugins> 
     <plugin> 
     <groupId>org.codehaus.cargo</groupId> 
     <artifactId>cargo-maven2-plugin</artifactId> 
     <version>1.0</version> 
     <configuration> 
      <container> 
       <containerId>tomcat6x</containerId> 
       <home> 
        C:\tools\apache-tomcat-6.0.26 
       </home> 
      </container> 
      <configuration> 
       <properties> 
        <cargo.servlet.port> 
         8082 
        </cargo.servlet.port> 
        <cargo.jvmargs> 
         "-Xdebug" "-Xrunjdwp:transport=dt_socket,address=4646,server=y,suspend=n" 
        </cargo.jvmargs> 
       </properties> 
      </configuration>  
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 

但是当我运行“命令mvn货物:启动”,Tomcat实例运行良好,但没有孩子的应用程序得到部署。有没有办法让我的第一个子应用程序(www)(它生成一个名为www-webapp-1.2.0.war的war文件)自动部署?

更新:感谢帕斯卡。我试图修改构建标签如下:

<build> 
    <plugins> 
     <plugin> 
     <groupId>org.codehaus.cargo</groupId> 
     <artifactId>cargo-maven2-plugin</artifactId> 
     <version>1.0</version> 
     <configuration> 
      <container> 
       <containerId>tomcat6x</containerId> 
       <home> 
        C:\tools\apache-tomcat-6.0.26 
       </home> 
      </container> 
      <configuration> 
       <properties> 
        <cargo.servlet.port> 
         8082 
        </cargo.servlet.port> 
        <cargo.jvmargs> 
         "-Xdebug" "-Xrunjdwp:transport=dt_socket,address=4646,server=y,suspend=n" 
        </cargo.jvmargs> 
       </properties>    
       <deployables> 
       <deployable> 
        <groupId>com.shc.obu.ca.osol</groupId> 
        <artifactId>www-webapp-1.2.0</artifactId> 
        <type>war</type> 
        <properties> 
        <context>acontext</context> 
        </properties> 
       </deployable> 
       </deployables>    
      </configuration>  
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 

但仍然不工作。它的构建错误如下:

工件[com.shc.obu.ca.osol:www-webapp-1.2.0:war]不是项目的依赖项。 我尝试了'www-webapp'和'www'作为工件ID,但错误仍然保持不变。

当我添加相同的产生依赖性的标签,它提供了某种如下循环引用错误的: “在反应器中的项目包含一个循环引用”

回答

2

你需要列出www模块作为模块在<deployable>元素内部署。从Maven2 Plugin Reference Guide

如果没有指定部署和项目的包装是战争,耳朵或EJB并没有那么指定部署生成的构件将被自动添加到deployables列表部署

由于您的项目的pom类型为packaing,因此它不适用于部署,也没有任何部署。

下面是一个例子:

<plugin> 
    <groupId>org.codehaus.cargo</groupId> 
    <artifactId>cargo-maven2-plugin</artifactId> 
    <version>1.0</version> 
    <configuration> 
     <container> 
     <containerId>tomcat6x</containerId> 
     <home>C:\tools\apache-tomcat-6.0.26</home> 
     </container> 
     <configuration> 
     <properties> 
      <cargo.servlet.port>8082</cargo.servlet.port> 
      <cargo.jvmargs> 
       "-Xdebug" "-Xrunjdwp:transport=dt_socket,address=4646,server=y,suspend=n" 
      </cargo.jvmargs> 
     </properties> 
     <deployables> 
      <!-- application to deploy --> 
      <deployable> 
      <groupId>com.acme</groupId> 
      <artifactId>mywebapp</artifactId> 
      <type>war</type> 
      <properties> 
       <context>acontext</context> 
      </properties> 
      </deployable> 
     </deployables> 
     </configuration>  
    </configuration> 
    </plugin> 

更新:

(...)它给建立如下错误

神器[com.shc.obu.ca .osol:www-webapp-1.2.0:war]不是项目的依赖项。我尝试了'www-webapp'和'www'作为工件ID,但错误仍然一样。

我忘记了这一点,但它看起来像货物期望一个deployable是货物开始项目的依赖项。

当我添加相同的产生依赖性的标签,它提供了某种如下循环引用错误的:“在反应器中的项目包含一个循环引用”

这是正常的。工件不能是给定项目的子模块和依赖项,或者您得到循环依赖项(您需要依赖项来构建依赖项,鸡和蛋问题的模块)。

我的建议是将货物配置移动到www模块或为您的功能测试创建一个专用模块(这通常是我所做的),并声明www为此模块的依赖关系。

+0

帕斯卡尔嗨, 能否请你帮我带两个其中U建议使用上面提供的POM代码的方法的样本。我尝试了第一种方法,然后得到一些错误,比如插件标签不能识别配置文件等,不知道如何实现第二种方法。 谢谢, Neeraj – Neeraj 2010-07-06 15:26:28

+0

@Neeraj:这表明POM无效。在配置文件中,插件应在' ...'中声明。 – 2010-07-06 17:08:36

+0

POM是有效的,我可以将整个构建标签移动到www profile中,但结果是一样的。我尝试了'mvn cargo:start'和'mvn -Pwww货物:开始',但我的应用程序www-webapp-1.2.0.war仍未部署或启动。 但是,如果我尝试运行'mvn -Pwww cargo:deploy'命令(在配置文件外部或内部使用构建标记),我的'www'war文件(www-webapp-1.2.0.war)确实会将副本发送到webapps货物下的文件夹。 – Neeraj 2010-07-07 11:35:17

1

以下是如何使用Cargo进行多模块部署的示例。它有一个母公司和三个模块,其中一个模块负责所有三个模块的部署。您可以从第三个模块运行mvn cargo:run以部署所有这些模块。

==================== PARENT 1 ========================= 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.blah.test</groupId> 
    <artifactId>blah-service</artifactId> 
    <packaging>pom</packaging> 
    <version>1.0-SNAPSHOT</version> 
    <modules> 
     <module>blah-service-module1</module> 
     <module>blah-service-module2</module> 
     <module>blah-service-module3</module> 
    </modules> 
</project> 

==================== MODULE 1 ========================= 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
     <groupId>com.blah.test</groupId> 
     <artifactId>blah-service</artifactId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 
    <artifactId>blah-service-module1</artifactId> 
    <packaging>war</packaging> 
    <version>1.0-SNAPSHOT</version> 
</project> 

==================== MODULE 2 ========================= 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
     <groupId>com.blah.test</groupId> 
     <artifactId>blah-service</artifactId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 
    <artifactId>blah-service-module2</artifactId> 
    <packaging>war</packaging> 
    <version>1.0-SNAPSHOT</version> 
</project> 

========== MODULE 3: the one which deploys all three with cargo ========================= 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <parent> 
     <groupId>com.blah.test</groupId> 
     <artifactId>blah-service</artifactId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 
    <artifactId>blah-service-module3</artifactId> 
    <packaging>war</packaging> 
    <version>1.0-SNAPSHOT</version> 

    <dependencies> 
     <dependency> 
      <groupId>com.blah.test</groupId> 
      <artifactId>blah-service-module1</artifactId> 
      <version>1.0-SNAPSHOT</version> 
      <type>war</type> 
     </dependency> 
     <dependency> 
      <groupId>com.blah.test</groupId> 
      <artifactId>blah-service-module2</artifactId> 
      <version>1.0-SNAPSHOT</version> 
      <type>war</type> 
     </dependency> 
    </dependencies> 


    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.codehaus.cargo</groupId> 
       <artifactId>cargo-maven2-plugin</artifactId> 
       <version>1.4.6</version> 
       <configuration> 
        <container> 
         <containerId>jetty6x</containerId> 
         <type>embedded</type> 
        </container> 
        <deployables> 
         <deployable> 
          <groupId>com.blah.test</groupId> 
          <artifactId>blah-service-module1</artifactId> 
          <type>war</type> 
          <properties> 
           <context>api/blah/module1</context> 
          </properties> 
         </deployable> 
         <deployable> 
          <groupId>com.blah.test</groupId> 
          <artifactId>blah-service-module2</artifactId> 
          <type>war</type> 
          <properties> 
           <context>api/blah/module2</context> 
          </properties> 
         </deployable> 
         <deployable> 
          <groupId>com.blah.test</groupId> 
          <artifactId>blah-service-module3</artifactId> 
          <type>war</type> 
          <properties> 
           <context>api/blah/module3</context> 
          </properties> 
         </deployable> 
        </deployables> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

</project>