2011-02-17 97 views
1

我有一個應該產生兩個工件(戰爭)的模塊。兩個WAR之間的唯一區別是正在使用的web.xml。
我這樣做是與Maven型材的幫助...Maven - 根據配置文件從父POM調用模塊

<parent> 
    <artifactId>com</artifactId> 
    <groupId>myProj</groupId> 
    <version>1.0</version> 
</parent> 

<groupId>myProj.module1</groupId> 
<artifactId>module1</artifactId> 
<version>1.0</version> 
<packaging>war</packaging> 

<profiles> 

    <profile> 
     <id>module1</id> 
     <build> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <configuration> 
        <warName>module1</warName> 
        <webXml>src\main\webapp\WEB-INF\web_module1.xml</webXml> 
       </configuration> 
      </plugin> 
      </plugins> 
     </build> 
    </profile> 


    <profile> 
     <id>module2</id> 
     <build> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <configuration> 
        <warName>module2</warName> 
        <webXml>src\main\webapp\WEB-INF\web_module2.xml</webXml> 
       </configuration> 
      </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 

Q1:我怎樣才能把這個從POM POM超級使得兩個配置文件被激活?
Q2:是否可以將生成的工件安裝在本地存儲庫中?

謝謝!

回答

2

當您想要activate several profiles at the same time時,您只需運行mvn ... -Pprofile1,profile2命令。

但是,在你的情況下,這是針對一個主要的Maven公約,其中指出one project = one artifact。這意味着您無法同時創建2個WAR。如果你激活了兩個配置文件,maven-war-plugin的一個配置將被第二個配置文件覆蓋,然後,你將最終得到1個WAR和一個web.xml。

如果你想獲得2個WAR,解決方法是使用WAR overlay(即第二場戰爭是另一個依賴戰爭#1的項目),或者運行兩個單獨的Maven命令,每個配置文件一個。

+1

謝謝romaintaz。有沒有什麼辦法可以通過個人資料的幫助來給我的孩子打個電話......可以做些什麼:` ....` – Arpit 2011-02-17 11:50:04