2010-07-05 58 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> 
相關問題