2013-03-27 32 views
3

讓我們假設我有一個Web項目和幾個可以部署它的環境。我希望Maven一次構建多個工件(例如,用於開發產品)。我有一個A-war模塊和一個A-ear模塊(包含A-war)。每件戰爭神器可能包含僅與其環境有關的信息。Maven ear插件多個工件內容

首先,我配置了戰模塊pom.xml文件:

<build> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <artifactId>maven-war-plugin</artifactId> 
       <executions> 
        <execution> 
         <id>package-prod</id> 
         <phase>package</phase> 
         <configuration> 
          <classifier>prod</classifier> 
          <webappDirectory>${project.build.directory}/${project.build.finalName}-prod</webappDirectory> 
          <webResources> 
           <resource> 
            <directory>src/env/prod</directory> 
           </resource> 
          </webResources> 
         </configuration> 
         <goals> 
          <goal>war</goal> 
         </goals> 
        </execution> 
        <execution> 
         <id>package-dev</id> 
         <phase>package</phase> 
         <configuration> 
          <classifier>dev</classifier> 
          <webappDirectory>${project.build.directory}/${project.build.finalName}-dev</webappDirectory> 
          <webResources> 
           <resource> 
            <directory>src/env/dev</directory> 
           </resource> 
          </webResources> 
         </configuration> 
         <goals> 
          <goal>war</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
    <finalName>A-war</finalName> 
</build> 

這工作得很好 - 2 * 戰爭 * s的目標文件夾中創建:A-戰爭督促和A-戰爭-dev的。

現在我想要構建耳朵神器這些戰爭中的每一個。

這裏是pom.xml中的在A-耳的主要內容模塊:

<dependencies> 
    <dependency> 
     <groupId>gr.id</groupId> 
     <artifactId>A-war</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
     <classifier>prod</classifier> 
     <scope>provided</scope> 
     <type>war</type> 
    </dependency> 
    <dependency> 
     <groupId>gr.id</groupId> 
     <artifactId>A-war</artifactId> 
     <classifier>dev</classifier> 
     <version>0.0.1-SNAPSHOT</version> 
     <scope>provided</scope> 
     <type>war</type> 
    </dependency> 

</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-ear-plugin</artifactId> 
      <version>2.8</version> 
      <executions> 
       <execution> 
        <id>package-dev</id> 
        <phase>package</phase> 
        <configuration> 
         <classifier>dev</classifier> 
         <version>5</version> 
         <modules> 
          <webModule> 
           <groupId>gr.id</groupId> 
           <artifactId>A-war</artifactId> 
           <classifier>dev</classifier> 
           <contextRoot>/A-war</contextRoot> 
           <bundleFileName>/A-war.war</bundleFileName> 
          </webModule> 
         </modules> 
        </configuration> 
        <goals> 
         <goal>ear</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>package-prod</id> 
        <phase>package</phase> 
        <configuration> 
         <classifier>prod</classifier> 
         <version>5</version> 
         <modules> 
          <webModule> 
           <groupId>gr.id</groupId> 
           <artifactId>A-war</artifactId> 
           <classifier>prod</classifier> 
           <contextRoot>/A-war</contextRoot> 
           <bundleFileName>/A-war.war</bundleFileName> 
          </webModule> 
         </modules> 
        </configuration> 
        <goals> 
         <goal>ear</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
    <finalName>A-ear</finalName> 
</build> 

它還建立2 耳** S:A-耳dev.ear和A-耳刺。耳。並且這些* 耳朵 *中的每一個都包含A-war.war神器。除了一個小細節之外,一切都會好的:這些** war文件是一樣的。我的意思是A-ear-dev.ear包含A-war-dev.war(它被重新命名爲A-war.war),但是A-ear-prod.ear包含相同的A-war-dev.war而不是它自己的A-戰爭prod.war。 此外,當我改變執行順序(移動創建高於dev的產品)時,這兩個包含A-war-prod.war。

,我可以從Maven的輸出,開始建設耳朵時看到**的IT拷貝第一戰成第一**耳的文件夾,但第二個它沒有:

[INFO] --- maven-ear-plugin:2.8:ear (package-dev) @ A-ear 
--- 
[INFO] Copying artifact [war:gr.id:A-war:dev:0.0.1-SNAPSHOT] to [/A-war.war] 
[INFO] Including custom manifest .... 
[INFO] Copy ear sources to ... 

[INFO] Building jar: <location>\A-ear\target\A-ear-dev.ear 

.... 
[INFO] --- maven-ear-plugin:2.8:ear (package-prod) @ A-ear --- 
[INFO] Copy ear sources to ... 
[INFO] Including custom manifest file ... 

[INFO] Building jar: <location>\A-ear\target\A-ear-prod.ear 

所以也許任何人有一個想法,如何每次強制maven副本war文件?

回答

5

正如我發現的,當Maven將war文件複製到臨時目錄中時,它不會重寫它 - 如果存在具有相同名稱的文件,則不會被替換。所以在第一個工件複製之後,它總是複製執行模塊中指向的第一個工件。 所有其他工件未被複制。所以這個神器被放置在所有的結果耳朵

所以對於這個問題的解決方法是指定的工作目錄爲每個執行標籤,如:

  <execution> 
       <id>package-prod</id> 
       <phase>package</phase> 
       <configuration> 
        <workDirectory>target/prod</workDirectory> 
        <classifier>prod</classifier> 
        <version>5</version> 
        <modules> 
         <webModule> 
          <groupId>gr.id</groupId> 
          <artifactId>A-war</artifactId> 
          <classifier>prod</classifier> 
          <contextRoot>/A-war</contextRoot> 
          <bundleFileName>/A-war.war</bundleFileName> 
         </webModule> 
        </modules> 
       </configuration> 
       <goals> 
        <goal>ear</goal> 
       </goals> 
      </execution>