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
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 SQS With JMS for Legacy Applications
  • Javac and Java Katas, Part 2: Module Path
  • Javac and Java Katas, Part 1: Class Path
  • Ways To Reduce JVM Docker Image Size

Trending

  • Kubeflow: Driving Scalable and Intelligent Machine Learning Systems
  • Beyond Linguistics: Real-Time Domain Event Mapping with WebSocket and Spring Boot
  • Microsoft Azure Synapse Analytics: Scaling Hurdles and Limitations
  • A Guide to Developing Large Language Models Part 1: Pretraining

Adding Version Information to your JAR’s Manifest

By 
Roger Hughes user avatar
Roger Hughes
·
Feb. 06, 12 · Interview
Likes (0)
Comment
Save
Tweet
Share
21.9K Views

Join the DZone community and get the full member experience.

Join For Free

One of the handy things about using Maven is that, by default, the names of the artifacts it creates include the current version number from the POM's version tag. It doesn’t matter what type of artifact it is, whether it’s a JAR, WAR or EAR you generally end up with something like this:

    my_module-1.2.3-RELEASE.jar

And this is all usually fine when you’re dealing with a project that’s built solely using Maven. It does, however, become a little more inconvenient if you’re developing JAR files with Maven, but your WAR file is developed using Ant. In this case, when you have to check files in to the /WEB-INF/libs directory yourself (perish the thought) and your JAR file changes often, you end up constantly adding and deleting files from your version control system. From experience, it turns out to be more convenient, in terms of file management, if you remove the version number from the JAR file name and use something like this:

    my_module.jar

However, there will always be the need to know the version of your JAR that has been included in your webapp’s WAR file and that’s where the maven-jar-plugin comes in handy. This allows you to write custom information into your JAR file’s manifest as shown by the POM file snippet below.

<build>
   <finalName>${project.artifactId}</finalName>
   <plugins>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-jar-plugin</artifactId>
         <version>2.3.2</version>
         <configuration>
            <archive>
               <index>true</index>
               <manifestSections>
                  <manifestSection>
                     <name>${project.name}</name>
                     <manifestEntries>
                        <mode>development</mode>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>${project.artifactId}</artifactId>
                        <version>${project.version}</version>
                     </manifestEntries>
                  </manifestSection>
               </manifestSections>
            </archive>
         </configuration>
      </plugin>
</build>

The POM file extract above contains two handy features. The first:

    <finalName>${project.artifactId}</finalName>

...removes the version number from the JAR file name by specifying the finalname tag. In this case the finalname has been set to the project.artifactId. This means that if your artifact tag looks something like this...

 <artifactId>my_module</artifactId>

...then your jar file will be called:

    my_module.jar

For more on Maven’s default properties take a look at this blog from last January.

The second task accomplished by the POM extract above is to use the maven-jar-plugin to add group, artifact and version information to the jar’s manifest file. The lines that are responsible for this are:

    <groupId>${project.groupId}</groupId>
    <artifactId>${project.artifactId}</artifactId>
    <version>${project.version}</version>

You can obviously add any information you want to a jar’s manifest file, but in this scenario, adding the version number was extremely useful when it came to support and tracing problems.

 

From http://www.captaindebug.com/2012/01/adding-version-information-to-your-jars.html

JAR (file format) Manifest (transportation)

Opinions expressed by DZone contributors are their own.

Related

  • Using SQS With JMS for Legacy Applications
  • Javac and Java Katas, Part 2: Module Path
  • Javac and Java Katas, Part 1: Class Path
  • Ways To Reduce JVM Docker Image Size

Partner Resources

×

Comments

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: