Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7041215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:00:43+00:00 2026-05-28T02:00:43+00:00

I come from ANT where you can invoke a .java file to obtain the

  • 0

I come from ANT where you can invoke a .java file to obtain the version number through executing some method. I would like to do something similar in my new pom.xml to automatically obtain the correct version number. I need the app to know about its own version and at the same time Maven to know about the version got make the right builds. Holding the version infomormation doubled is no option.

Or can Maven create a new .java file during/before building?

I can image quite a few ways to achive this, but is there a best practise way to do this in Maven project?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:00:44+00:00Added an answer on May 28, 2026 at 2:00 am

    When building a JAR, Maven writes the pom.xml and a pom.properties file into META-INF/maven/[group ID]/[artifact ID] directory. You can then read the version out of one of these in your application.

    Alternatively, you can explicitly write a new version.properties file by using resource filtering.

    If you put the following in your POM:

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>
    

    and then put a version.properties template into the src/main/resources directory that looks like:

    version = ${project.version}
    

    Maven will substitute in the version read out of the POM, and your application then just needs to read the version.properties resource and query the version key.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I come from the Java world, where you can hide variables and functions and
I come from a java background. But I would like a cross-platform perspective on
I come from a background in static languages. Can someone explain (ideally through example)
I come from a Java background, where packages are used, not namespaces. I'm used
I come from more of a Java background. In the last year or two,
I come from a Java background and with any servlets-based technology, it's trivial to
I come from an ant background, and I'm starting to use msbuild. I want
I come from an ASP .Net background. I am now writing a Java program
I come from a C/C++ background and am having trouble doing some things in
I come from a PHP background and would like to know if there's a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.