2011-02-08 37 views
15

我們的政策是隻構建一個可部署的jar。所有環境特定的配置都保持獨立,我們一起構建它們。所以在我們當前的Ant過程中,我們爲每個環境都有一個屬性文件,循環它們,併爲每個環境創建一組配置文件。Maven一次構建多個配置文件

在我目前的POM XML中,我只能在命令行中構建一個配置文件。是否有可能通過Maven實現?

這裏有一些的pom.xml

<!-- Define profiles here and make DEV as default profile --> 
<profiles> 

    <!-- dev Profile --> 
    <profile> 
     <id>dev</id> 
     <activation> 
      <activeByDefault>true</activeByDefault> 
     </activation> 
    </profile> 

    <!-- qa Profile --> 
    <profile> 
     <id>qa</id> 
     <properties> 
      <env>qa</env> 
     </properties> 
    </profile> 

    <!-- prod Profile --> 
    <profile> 
     <id>prod</id> 
     <properties> 
      <env>prod</env> 
     </properties> 
    </profile> 

</profiles> 
... 


<plugin> 
    <artifactId>maven-resources-plugin</artifactId> 
    <version>2.4.3</version> 

    <executions> 
     <execution> 

      <phase>validate</phase> 
      <goals> 
       <goal>copy-resources</goal> 
      </goals> 

      <configuration> 

       <filters> 
        <filter>env/${env}.properties</filter> 
       </filters> 

       <outputDirectory>${project.build.directory}/config/${env} 
       </outputDirectory> 
       <resources> 
        <resource> 

         <filtering>true</filtering> 

         <directory>${basedir}/src/main/config/default 
         </directory> 
         <includes> 
          <include>*.xml</include> 
          <include>*.properties</include> 
         </includes> 
        </resource> 

的相關部分的.....

感謝, Prabhjot

+0

這裏描述的解決方法爲: https://stackoverflow.com/questions/12320322/build-multiple-artifacts-with-different-classifiers-at-once – stokito 2015-06-30 11:32:09

回答

19

Maven是不喜歡螞蟻。用螞蟻,你可以基本上做你想做的事情。有了maven,有一個明確的文檔build life cycle,它的目標是構建一個組件(並可能將其他工件附加到構建中)。

然而,您打算做的是多次構建一個組件,但使用不同的參數。這不適合Maven的生命週期。所以你需要做的是引起一些外部進程做迭代,並用不同的參數重複調用maven。

完成此操作的經典方法是使用shell腳本,但您也可以使用Maven Invoker從Java或Maven上下文啓動單獨的進程。

相關問題