Retrieve app version from maven pom.xml in java

Today we will discuss working with pom.xml. Suppose you have a web application and you want to print its current version in some part of the page.
Of course, you can save the version in a separate parameter and read from there. But there is an option better. We can determine the version by reading it directly from pom.xml.

Coding

Create a new maven project. To work with the Maven model, we will use the maven-model library.
Add the maven-model dependencies

Create an empty Main  class. In the created class, add the code:

Result

Here’s what we get as a result of running the program:

Need to retrieve pom version from CLI? Check this example

2 Comments on “Retrieve app version from maven pom.xml in java”

  1. Thanks for the article ‘Retrieve app version from maven pom.xml in java’ . It helped me.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.