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

  • Home
  • SEARCH
  • 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 8680041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:08:36+00:00 2026-06-12T21:08:36+00:00

My team are doing with 2 teams: server team and client team. We at

  • 0

My team are doing with 2 teams: server team and client team. We at server team will provide APIs for the client team to call. The APIs have many version, so that we need to match the server build and the respective client build – for example, the old client will refuse to work if the server build number is much larger than its support version and requires an update.

Because of the above reason, we need to send back the build version of server to client. Currently we are doing this by adding a static field in a Config class. But I’m concerned with the fact that we must manually increase it everytime a new server is built – especially when we do daily build. This process is quite error-prone and not quite elegant.

In my search, I see many propose for using maven plugins to manage the build version. Though I highly appreciated the auto-process, it still doesn’t let the server know the build number. Server application should be able to return its build version to client through an API call.

I have thought of write the number version somewhere (remote database, files on server).
Is there any way to make the building process automatically increase the build version, but the application itself can retrieve this number in running also?

We are using Maven build and having Jenkin as the integration build server.

  • 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-06-12T21:08:37+00:00Added an answer on June 12, 2026 at 9:08 pm

    I usually read the version from the MANIFEST.MF file that is packaged in the JAR by Maven.
    By default it looks something like this:

    Manifest-Version: 1.0
    Built-By: user
    Build-Jdk: 1.6.0_35
    Created-By: Apache Maven 3.0.4
    Archiver-Version: Plexus Archiver
    
    Name: Artifact
    Implementation-Build: 1.14-SNAPSHOT
    Version: 1.14-SNAPSHOT
    

    From this file I read the Version element and use that to for instance display the build version of the application (and all versions of the packaged jars in a WAR/EAR for instance).
    Something like this code should work:

    public static String getApplicationVersion() {
            String version = null;
            try {
                final List<VersionsUtil.Version> moduleVersions = VersionsUtil.getModuleVersions(Thread.currentThread().getContextClassLoader());
                for (VersionsUtil.Version moduleVersion : moduleVersions) {
                    if (moduleVersion.name.equals("<NAME OF ARTIFACT TO GET>")) {
                        version = moduleVersion.version;
                        break;
                    }
                }
            } catch (IOException e) {
                // We'll return null...
            }
            return version;
        }
    
    
    public class VersionsUtil {
        private static final Logger LOG = LoggerFactory.getLogger(VersionsUtil.class);
    
        /**
         * Returns a list of the module versions available for the given class loader.
         *
         * @param classLoader the class loader to return module versions for
         * @return a list of module versions
         * @throws IOException in case there's an error reading the manifest
         */
        public static List<Version> getModuleVersions(final ClassLoader classLoader) throws IOException {
            return processResources(classLoader.getResources("META-INF/MANIFEST.MF"));
        }
    
        private static List<Version> processResources(final Enumeration<URL> resources) throws IOException {
            final List<Version> moduleVersions = new ArrayList();
            while (resources.hasMoreElements()) {
                URL resource = resources.nextElement();
                Version v = process(resource);
                if (v != null) {
                    moduleVersions.add(v);
                }
            }
            return moduleVersions;
        }
    
        private static Version process(final URL resource) {
            try {
                Properties p = readResource(resource);
                return createVersion(p);
            } catch (IOException e) {
                LOG.warn("Failed to read resource: " + resource, e);
                return null;
            }
        }
    
        private static Version createVersion(final Properties p) {
            Object name = p.get("Name");
            if (name != null) {
                return new Version((String) name, (String) p.get("Version"));
            }
            return null;
        }
    
        private static Properties readResource(final URL resource) throws IOException {
            LOG.trace("Reading resource: " + resource);
            InputStream is = resource.openStream();
            Properties p = new Properties();
            p.load(is);
            is.close();
            return p;
        }
    
        public static final class Version {
            String name;
            String version;
    
            private Version(final String name, final String version) {
                this.name = name;
                this.version = version;
            }
    
        }
    }
    

    Updated:
    If you want Jenkins buildnumber in the MANIFEST.MF you can configure your POM.XML with something like:

      ...
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <archive>
            <manifestSections>
              <manifestSection>
                <name>${project.name} (${project.artifactId})</name>
                <manifestEntries>
                  <Version>${project.version}${build.number}</Version>
                </manifestEntries>
              </manifestSection>
            </manifestSections>
          </archive>
        </configuration>
      </plugin>
      ...
      <properties>
         <build.number />
      </properties>
      ...
    

    If you’re interested in tagging the WAR/EAR files instead, you have to add the manifest configurations accordingly.
    Then in your Jenkins job configuration, simply pass the BUILD_NUMBER parameter to the maven process like this: -Dbuild.number=$BUILD_NUMBER.

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

Sidebar

Related Questions

Team, I have an ASP.NET MVC application that I'm deploying. When I deploy it
Team Foundation Server 2008 allows that every check-in is associated with a work item,
my team have built many tools for our project using win forms and Visual
I'm trying to set up a new Team Build Server for doing continuous integration,
I have a test project that I want to automate on a test server.
I work in VS2008 Team. I get the latest version from the team server.
I have a folder in Team Foundation Server with several sub-folders: candidates beta1 beta2
My team and I are working on an API/Middleware system that will require all
So we decided to go with visual studio team foundation server for version control,
When doing larger sites in big business, you most probalbly work in a team

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.