What's the most efficient way of displaying the version number contained in a POM file in my Angular App?
I have a REST application running on Tomcat.
I guess there are a couple of options
- Have a REST service that just delivers the version number of the application
- Create a text file during the mvn build and copy that into the web app, then read the file from the front end
Has anyone encountered this before?
The typical way of doing that is by adding a placeholder for the version in some file of your web-application and replacing that placeholder at compile time:
- Add the placeholder
${project.version}
in a file of your choice under src/main/webapp
.
Configure the maven-war-plugin
like this:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
This plugin will replace the placeholder ${project.version}
with the current Maven version at build time.
The rest of your application can now access the Maven version as if it were a simple hard-coded String.
You can use maven replacer plugin to replace specific pattern in files (web pages) by version from pom during build. example:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${warSourceDirectory}/index.html</file>
<replacements>
<replacement>
<token>%PROJECT_VERSION%</token>
<value>${project.version}</value>
</replacement>
</replacements>
</configuration>
</plugin>