Maven filtering - replacement of variables

Viewed 390

I have a maven project, which generates a jar file as a web project. Based on Maven I include a standalone Tomcat. Inside of the jar file, there is actually the war-file, which contains my application.

This application contains a "version.txt" in src/main/config (or any similar path), that is finally included in the war-file.

This version.txt looks like:

version: ${project.version}

I would like, that maven should replace the variable with the correct version from pom.xml. In my pom.xml I have included:

  <build>
    <resources>
      <resource>
        <directory>src/main/config</directory>
          <filtering>true</filtering>
            <includes>
              <include>**/version.txt</include>
            </includes>
          </resource>
        <resource>
      <resources>
  </build>

So is there any way to include this version.txt and a working replacement in a war-file, which is in a (Tomcat)jar-file?

Addendum:

My File hierarchy looks like:

jar-file
-- ...
--war-file
---- ...
----version.txt
2 Answers

Thanks for the advice. No, there was no maven-war-plugin, but I have included it and based on the instructions, it works.

Short solution:

Added a resourceDirectory on same level like pom.xml and included version.txt

Added in pom.xml and activate filtering:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.3.1</version>
        <configuration>
            <webResources>
                <resource>
                    <filtering>true</filtering>
                    <directory>externalresources</directory>
                </resource>
            </webResources>
        </configuration>
    </plugin>
Related