Paul Zepernick
Paul Zepernick

Reputation: 1462

Maven maven-war-plugin not replacing values in web.xml

Maven version: 3.5.4

My web directory is not in the standard location. It is in /web

Maven War config

 <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.2</version>
            <configuration>
                <webResources>
                    <!--
                        Filter these files to look for ${my.maven.property} to replace them
                        at build time with a maven property value
                    -->
                    <resource>
                        <filtering>true</filtering>
                        <directory>web/WEB-INF</directory>
                        <includes>
                            <include>**/web.xml</include>
                        </includes>
                    </resource>
                </webResources>
                <warSourceDirectory>web</warSourceDirectory>
                <failOnMissingWebXml>true</failOnMissingWebXml>
                <webXml>web/WEB-INF/web.xml</webXml>
                <packagingExcludes>
                   ${exclude.files.on.build}
                </packagingExcludes>
            </configuration>
        </plugin>

properties snippet from pom.xml

  <properties>
       ...

       <!-- web.xml vars -->
       <web.session.cookie.secure>true</web.session.cookie.secure> <!-- session cookie only sent over https -->
      ...
 </properties>

web.xml snippet

   <cookie-config>
        ...
        <secure>${web.session.cookie.secure}</secure>
        ...
    </cookie-config>

The property "${web.session.cookie.secure}" is not being replaced in the web.xml, and the property name is retained in the war file generated. I have not been able to pinpoint the configuration error. I am working in Intellij and get the same result whether I build the artifact off the intellij menu, or issue the mvn war:exploded command.

I am assuming that it may have something to do with the web directory location and a missing configuration item. The maven build runs as expected other than the issue with the properties not being replaced in the output.

Any ideas as to why the replacements would not be taking place using the filtering of the maven-war-plugin?

Upvotes: 0

Views: 609

Answers (1)

briadeus
briadeus

Reputation: 605

The maven-war-plugin uses ${basedir} as the location of the pom, so the target directory for filtering should be referenced via relative path from there.

<resource>
  <filtering>true</filtering>
  <directory>${basedir}/web/WEB-INF</directory>
  <includes>
    <include>**/web.xml</include>
  </includes>
</resource>

The actuall path could be examined in mvn help:effective-pom.

Upvotes: 1

Related Questions