如何在web.xml的maven-war-plugin中设置display-name

chi*_*.de 4 web.xml maven maven-war-plugin

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

在maven-ear-plugin中,有一个配置选项displayName来设置EAR/application.xml display-name属性.

错误的做法?只需在web.xml中手动设置它?

Fre*_*con 8

您需要使用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>
Run Code Online (Sandbox Code Playgroud)

在您的web.xml中,您可以使用pom.xml中定义的任何属性.所以你可以使用:

<display-name>${project.name} - ${project.version}</display-name>
Run Code Online (Sandbox Code Playgroud)

这将呈现为

<display-name>My Awesome Webapp - 1.0.0-SNAPSHOT</display-name>
Run Code Online (Sandbox Code Playgroud)

如果您使用Eclipse,则需要m2e-wtp(请查看主页中的Web资源过滤截屏视频)