DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Using Python Libraries in Java
  • DGS GraphQL and Spring Boot
  • How to Build a New API Quickly Using Spring Boot and Maven
  • Configurable Feign Client Retry With Reusable Library and DRY

Trending

  • Revolutionizing Financial Monitoring: Building a Team Dashboard With OpenObserve
  • AWS to Azure Migration: A Cloudy Journey of Challenges and Triumphs
  • Why Database Migrations Take Months and How to Speed Them Up
  • Memory Leak Due to Time-Taking finalize() Method
  1. DZone
  2. Coding
  3. Java
  4. How to Display Maven Project Version in Your Webapp Overview

How to Display Maven Project Version in Your Webapp Overview

By 
Vineet Manohar user avatar
Vineet Manohar
·
Sep. 23, 10 · Interview
Likes (0)
Comment
Save
Tweet
Share
36.3K Views

Join the DZone community and get the full member experience.

Join For Free

sometimes it is useful to display the version of your web application, typically in the footer area of the web page. by displaying the version information, one can quickly determine which version of the app is running or users can use it for error reporting purposes. displaying the version is also useful when there are frequent automated releases using the maven release plugin and it is hard to track which version is actually deployed on a server. here’s an illustration of how version can be displayed in the footer.

project version shown in footer

this article describes how to display the version of your maven project in your web application.

step 1: create a view file to display the version

first we will create a view file which will display the version. the view file could be a jsp, html, xhtml, a facelet or any format depending on your stack. in this example, we will create a jsp file which will print the version somewhere in the page. however, instead of the hardcoding an actual version, we put a special token ‘project_version’. we don’t want to hard code the version information as it will change from release to release. the special token will be replaced with actual maven project version when the app is packaged.

create the following jsp.

src/main/webapp/version.jsp 

here’s a simple file which displays the version information.

 <html>
  <body>project version is <i>project_version</i></body>
</html>

step 2: add snippet to pom.xml

the maven replacer plugin is a simple and useful plugin which can replaces tokens in file of your choice. add the following snippet of code to your pom.xml.

<project>
 <build>
  <plugins>
   <!-- replace version in file -->
   <plugin>
    <groupid>com.google.code.maven-replacer-plugin</groupid>
    <artifactid>maven-replacer-plugin</artifactid>
    <version>1.3.2</version>
    <executions>
     <execution>
      <!-- the replace should happen before the app is packaged -->
      <phase>prepare-package</phase>
      <goals>
       <goal>replace</goal>
      </goals>
     </execution>
    </executions>

    <configuration>
     <includes>
      <!-- replace the token in this file -->
      <include>target/myproject/version.jsp</include>
     </includes>
     <regex>false</regex>
     <!-- the name of the token to replace -->
     <token>project_version</token>
     <!-- replace it with the maven project version -->
     <value>${project.version}</value>
    </configuration>
   </plugin>
  </plugins>
 </build>
</project>

to test the above setup, you can run the following command:

mvn prepare-package

navigate to the following file.

target/myproject/version.jsp

the contents of this file will look something like this (assuming that your project version is 1.0-snapshot):

<html>
  <body>project version is <i><strong>1.0-snapshot</strong></i></body>
</html>

when your application ships, the version.jsp file will always have the correct version. you can see the version by invoking the version.jsp page.

http://localhost:8080/myproject/version.jsp 

note:

  • your view file does not have to be a jsp, it can be any a view file suitable to your stack. it could be part of your footer which could be included at the bottom in each page.
  • the special token can be changed from project_version to another value of your choice, just change it in the view file as well as the pom.xml
  • instead of having the version contained in a view file, you could have the version in a properties file or a message bundle and then display a message from the message bundle on the view

references

  • maven replace plugin on google code

from http://www.vineetmanohar.com/2010/09/how-to-display-maven-project-version-in-your-webapp

Apache Maven

Opinions expressed by DZone contributors are their own.

Related

  • Using Python Libraries in Java
  • DGS GraphQL and Spring Boot
  • How to Build a New API Quickly Using Spring Boot and Maven
  • Configurable Feign Client Retry With Reusable Library and DRY

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!