2013-07-02 57 views
0

我有一个JEE6 web应用程序项目。该项目结构符合maven约定。有条件包含maven中的文件

现在我已经为这个项目引入了额外的web.xml文件。

所以他们现在都存储在WEB-INF如下:

WEB-INF/

 |__ A/web.xml 

    |__ B/web.xml 

什么是Maven的方式来建立一个战争,包括根据财产正确的XML。

我知道如何在maven中添加自定义属性。但我找不到如何配置maven插件,以便在构建war文件时选择合适的文件。

在这种情况下,任何提示/建议/ maven最佳实践是最受欢迎的。

谢谢!

回答

3

maven war plugin可以配置为添加和过滤一些外部资源。见http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html

所以我会用2个行家profiles像这样2战插件配置:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-war-plugin</artifactId> 
    <version>2.3</version> 
    <configuration> 
     <webResources> 
     <resource> 
      <!-- this is relative to the pom.xml directory --> 
      <directory>src/main/webapp/WEB-INF/__A</directory> 
      <includes> 
      <include>web.xml</include> 
      </includes> 
      <targetPath>WEB-INF</targetPath> 
     </resource> 
     </webResources> 
    </configuration> 
    </plugin> 
    <!-- repeat for your second profile --> 

,但我认为一个更好的解决方案(如果您的项目允许的话)将只保留一个web.xml文件在里面有一些过滤的属性。在这种情况下,你应该只是配置你的战争插件来启用一些像这样的过滤:

<plugin> 
    <artifactId>maven-war-plugin</artifactId> 
    <version>2.3</version> 
    <configuration> 
     <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors> 
    </configuration> 
    </plugin> 
相关问题