2

In my Maven multi-module project (you can have a look here for other details), I've enabled web.xml filtering for the webapp module, so that I can reference Maven properties in there.

I defined:

  1. a property in the webapp module POM;
  2. a property in the parent POM;
  3. the Maven <name /> element in the parent POM.

The properties in [1] and [2] are both expanded correctly in the packaged web.xml file, but the parent <name /> tag is not — if I declare that element in the webapp-module it is correclty expanded.

Am I missing something? Is this the expected behaviour?


Here are the relevant parts of the various XML files involved.

filtered (final) web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

    <display-name>shaker-multi-webapp webapp-value parent-value 1.0</display-name>
</web-app>

web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

    <display-name>${project.name} ${webapp.prop} ${par.prop} 1.0</display-name>
</web-app>

Webapp POM

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>sunshine.web</groupId>
        <artifactId>shaker-multi</artifactId>
        <version>0.0.1</version>
    </parent>

    <artifactId>shaker-multi-webapp</artifactId>
    <packaging>war</packaging>

Parent POM

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>sunshine.web</groupId>
    <artifactId>shaker-multi</artifactId>
    <version>0.0.1</version>
    <packaging>pom</packaging>

    <name>Shaker</name>

    <modules>
        <module>shaker-multi-core</module>
        <module>shaker-multi-runnable</module>
        <module>shaker-multi-webapp</module>
        <module>shaker-multi-webapp-muserver</module>
    </modules>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <par.prop>parent-value</par.prop>
    </properties>
Community
  • 1
  • 1
watery
  • 5,026
  • 9
  • 52
  • 92

1 Answers1

3

To get the name declared in the parent POM, ${parent.name} should be used instead of ${project.name}, since project names aren't inherited (find more details in Maven sources).

Credits go to rfscholte from #maven@irc.codehaus.org.

watery
  • 5,026
  • 9
  • 52
  • 92
  • 1
    Let's call it "A solution", not "The solution" ;) Most important is to know that the name is not inherited. I would probably choose for specifying the name in the pom of the webapp-module, since every project name should be unique (also nice to see in the console output). – Robert Scholte Sep 23 '14 at 21:03