3
votes

If I add the following property in my POM, the maven-war-plugin uses it correctly:

<properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>
</properties>

However if I add the following property the plugin ignores it (the generated WAR has the default name, i.e. artifactId-version):

<properties>
    <war.warName>${project.artifactId}</war.warName>
</properties>

Here are two excerpts from the maven-war-plugin documentation:

warName:

  • The name of the generated WAR.
  • Type: java.lang.String
  • Required: Yes
  • User Property: war.warName
  • Default: ${project.build.finalName}

failOnMissingWebXml:

  • Whether or not to fail the build if the web.xml file is missing. Set to false if you want you WAR built without a web.xml file. This may be useful if you are building an overlay that has no web.xml file.
  • Type: boolean
  • Since: 2.1-alpha-2
  • Required: No
  • User Property: failOnMissingWebXml
  • Default: true

(Source: https://maven.apache.org/plugins/maven-war-plugin/war-mojo.html)

Why is the behavior different between failOnMissingWebXml and war.warName?

Also, if other plugins can use the value ${project.build.sourceEncoding} why can't maven-war-plugin use the value of ${project.build.finalName}?

<properties>
    <!-- plugins use these values correctly -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <failOnMissingWebXml>false</failOnMissingWebXml>

    <!-- not "found" by maven-war-plugin -->
    <war.warName>${project.artifactId}</war.warName>
    <project.build.finalName>${project.artifactId}</project.build.finalName>
</properties>

Thanks a lot! :)

EDIT: Since the version 2.4 of maven-war-plugin war.warName works as expected, however I still don't understand why setting project.build.finalName doesn't work.

1
which version of the maven war plugin are you using?A_Di-Matteo
Ha! I didn't have anything in <build> so the default version that maven uses is 2.2. I've force it to use the 2.6 and war.warName is used correctly... Thanks. Their documentation should be updated though...nyg

1 Answers

3
votes

The problem is simply that you mistaken property cause user property is meant to be used usually from command like this:

mvn -Dwar.warName=xxx war:war

If you like to use it in a pom file you have to use it like this:

  <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <warName>WhatEverYouLike</warName>
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  ...

And you shouldn't use properties in your pom to define such things. Better use the configuration tag for this.

The ${project.build.finalName} should be used like this:

<project..>
  <build>
    <finalName>WhatYouLIke</finalName>
    ..
  </build>
</project>

The structure can be seen if you look into the maven model.

The usage of ${project.build.sourceEncoding} is simply a convention in Maven plugins so you could define that property which is picked up by a larger number of plugins to be used for source encoding (I have to admit this is a little bit misleading). The original idea behind was having something in the maven model to represent the encoding which would mean to change it which is not really possible at the moment.