I am working on a java web application, managed by maven2. From time to time, we did some changes, and want to do new releases, of course with new version number. In the homepage (jsp), there is text like
<b>version:</b> 2.3.3...
Is it possible, every time I do a new release, I only change the <version/>
in pom.xml, and version number in jsp can be automatically filled by this maven ${project.version}?
I tried maven profile, however it doesn't seem to work.
any ideas?
Thank you.
Project versions - these are basically snapshots of a project at different stages of a project. Based on how the system is set up, a version could be created everytime the system status of a project object is changed, for example.
The plugin is part of the Maven Super Pom and executed during the process-resources phase of the Jar Default Lifecyle. The only thing you have to do is to active filtering. How you make this property then available to your Java application is up to you - reading it from the classpath would work.
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>
It's maybe stupid but I'd use a .properties
file like in this example instead of filtering directly the JSP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With