我有一个 JEE6 Web 应用程序项目。项目结构符合 Maven 约定。
现在我为这个项目引入了额外的 web.xml 文件。
所以它们现在存储在 WEB-INF 中,如下所示:
WEB-INF/
|__ A/web.xml
|__ B/web.xml
构建 war 以根据属性包含正确的 xml 的 Maven 方法是什么。
我知道如何在 Maven 中添加自定义属性。但我找不到如何配置 Maven 插件,以便在构建 War 文件期间选择适当的文件。
在这种情况下任何提示/建议/maven 最佳实践都是非常受欢迎的。
谢谢!!
最佳答案
maven war plugin可以配置为添加和过滤一些外部资源。请参阅http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html .
所以我会制作 2 个 Maven profiles有 2 个 war 插件配置如下:
<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 文件,其中包含一些过滤的属性。在这种情况下,您应该配置您的 war 插件来启用一些过滤,如下所示:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
</configuration>
</plugin>
关于java - 在maven中条件包含文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17430839/