Search code examples
javamaventomcattomcat7

Maven filtering - replacement of variables


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

Solution

  • I suggest you use the maven-war-plugin.

    https://maven.apache.org/plugins/maven-war-plugin/usage.html

    It will expect a certain directory layout, and in the examples it clearly shows how to filter (replace maven variables into the web resources)

    https://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html

    If this solution falls short, then a more specific question based on this should should be asked later.