简体   繁体   中英

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM