mavenjakarta-eewarcontext.xmlmaven-resources-plugin

How to expand Maven properties in all files within src/main/webapp?


I'd like to include some Maven properties(*) in src/main/webapp/META-INF/context.xml.

(*) E.g. ${data-source-name}, ${data-source-factory}, ${jdbc-connection-url} etc. - but in the words of the late, great Leslie Nielsen, that's not important right now.

Thought this might be achievable using something like the following maven-resource-plugin config:

<build>
  <resources>
    <resource>
      <directory>src/main/webapp</directory>
      <includes>
        <include>**/*</include>
      </includes>
      <filtering>true</filtering>
    </resource>
  </resources>
</build>

But this results in two versions of context.xml in the WAR file:

\META-INF\context.xml                 <=== Properties *not* expanded
\WEB-INF\classes\META-INF\context.xml <=== Properties expanded

Where am I going wrong?


Solution

  • After a bit more googling I found out how to do it using the maven-war-plugin instead of the maven-resources-plugin:

    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-war-plugin</artifactId>
          <configuration>
            <webResources>
              <resource>
                <directory>src/main/webapp</directory>
                <filtering>true</filtering>
              </resource>
            </webResources>
          </configuration>
        </plugin>
      </plugins>
    </build>