Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set display-name in maven-war-plugin for web.xml

How can I define the web.xml display-name via maven using the maven-war-plugin?

In maven-ear-plugin there is an configuration option displayName to set the EAR / application.xml display-name attribute.

Wrong approach? Just set it manually in web.xml?

like image 271
childno͡.de Avatar asked Dec 17 '22 00:12

childno͡.de


2 Answers

You need to use Maven's web resource filtering approach. Set the following configuration in your 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>

And in your web.xml, you can use any properties defined in your pom.xml. So you could for instance use :

<display-name>${project.name} - ${project.version}</display-name>

That would be rendered as

<display-name>My Awesome Webapp - 1.0.0-SNAPSHOT</display-name>

If you use Eclipse, you'll need m2e-wtp (look at the web resource filtering screencast in the home page)

like image 200
Fred Bricon Avatar answered Jan 13 '23 05:01

Fred Bricon


Much more simplier...

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

see filteringDeploymentDescriptors's documentation. This is available since 2.1 but is disabled per default.

like image 34
Cizar Avatar answered Jan 13 '23 04:01

Cizar