【发布时间】:2012-05-08 12:55:16
【问题描述】:
如何使用 maven-war-plugin 通过 maven 定义 web.xml 显示名称?
在 maven-ear-plugin 中有一个配置选项 displayName 来设置 EAR / application.xml display-name 属性。
错误的方法?直接在web.xml中手动设置?
【问题讨论】:
标签: maven web.xml maven-war-plugin
如何使用 maven-war-plugin 通过 maven 定义 web.xml 显示名称?
在 maven-ear-plugin 中有一个配置选项 displayName 来设置 EAR / application.xml display-name 属性。
错误的方法?直接在web.xml中手动设置?
【问题讨论】:
标签: maven web.xml maven-war-plugin
您需要使用 Maven 的 web resource filtering 方法。在您的 maven-war-plugin 中设置以下配置:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<webResources>
<resource>
<directory>src/main/webapp/WEB-INF/</directory>
<targetPath>WEB-INF</targetPath>
<includes><include>web.xml</include></includes>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
在您的 web.xml 中,您可以使用 pom.xml 中定义的任何属性。所以你可以例如使用:
<display-name>${project.name} - ${project.version}</display-name>
这将被呈现为
<display-name>My Awesome Webapp - 1.0.0-SNAPSHOT</display-name>
如果您使用 Eclipse,则需要m2e-wtp(查看主页中的网络资源过滤截屏视频)
【讨论】:
更简单...
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
</configuration>
</plugin>
请参阅filteringDeploymentDescriptors 的文档。这从 2.1 开始可用,但默认情况下被禁用。
【讨论】: