如何在 maven-war-plugin for web.xml 中设置显示名称



如何使用 maven-war-plugin 通过 maven 定义 web.xml 显示名称?

在 maven-ear-plugin 中,有一个配置选项 displayName 来设置 EAR/应用程序.xml显示名称属性。

错误的方法?只需在 Web 中手动设置.xml?

您需要使用 Maven 的 Web 资源过滤方法。在你的 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(查看主页中的 Web 资源过滤截屏视频)

更简单...

<plugin>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.4</version>
  <configuration>
    <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
  </configuration>
</plugin>

请参阅筛选部署描述符的文档。此功能从 2.1 开始可用,但默认情况下处于禁用状态。

最新更新