Retrieve 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 retrieve pom version from cli? Check this example

Related Post

1 thought on “Retrieve version from maven pom.xml in java”

Leave a Reply

Your email address will not be published. Required fields are marked *