How can I in a jsp page get maven project version number?

It's maybe stupid but I'd use a .properties file like in this example instead of filtering directly the JSP.


You can use project filtering to process the JSP as it is copied to the target location. If the JSP is specified with ${project.version}, and the containing folder is specified as a filter location the value should be substituted into the JSP as it is packaged.

For example, adding this to your POM enables filtering for src/main/resources:

<resources>
  <resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
  </resource>
</resources>

Update: for war packaging, you may need to configure the war plugin to do its filtering. See the Filtering section of the war-plugin's documentation for more details and examples.

Essentially the process is the same, but it is defined below the war plugin, so you'd have something like this:

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

Tags:

Java

Maven 2