Fork me on GitHub jcabi

23-Sep-2013 0.8

Static Reader of META-INF/MANIFEST.MF Files

com.jcabi.manifests.Manifests is a convenient static reader of META-INF/MANIFEST.MF files. Try this:

import com.jcabi.manifests.Manifests;
public class Main {
  public static void main(String[] args) {
    String version ="JCabi-Version");
    System.out.println("version is " + version);

As Oracle documentation says the META-INF/MANIFEST.MF is a special file that can contain information about the files packaged in a JAR file. Every JAR file in your classpath contains its own manifest. Every manifest consists of attributes and values. For example, this is META-INF/MANIFEST.MF of junit-4.10.jar:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.6.0_26-b03-384-10M3425 (Apple Inc.)

This manifest was generated by the author of JUnit JAR package and contains three attributes Manifest-Version, Ant-Version, and Created-By. When a JAR package is available in the classpath your application can retrieve these attributes from its manifest. Manifests utility class is a convenient reader of all attributes from all manifest files available in the classpath. All you need to provide is a name of the desired attribute.

MANIFEST.MF files may become an effective alternative to .properties files when Manifests utility class is used. You don't need to worry about finding the right location of the right .properties, loading it into memory, and dealing with exceptions. All you do is reading from Manifests:

public class Main {
  public static void main(String[] args) {
    System.out.println("JAR was created by " +"Created-By"));

To put information into your manifest maven-jar-plugin or maven-war-plugin can be used, for example:


After packaging of the WAR artifact its MANIFEST.MF file will contain this attribute (among some others):

Foo-Version: 1.0-SNAPSHOT

Read more about using MANIFEST.MF file for versioning of your Java application. Also pay attention to the difference between JAR and WAR applications. Besides that, there is a number of best practices related to unit testing and mocking of MANIFEST.MF attributes.

The only dependency you need in your class path is (you can also download jcabi-manifests-0.8.jar and add it to the classpath):


If you are outside of WAR application you should add Servlet API to compile-time classpath:


Cutting Edge Version

If you want to use current version of the product, you can do it with this configuration in your pom.xml:


Copyright © 2012-2013, All Rights Reserved. Privacy Policy.

site is built by Apache Maven