2013-03-27 60 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>