Question: I'm trying to read my META-INF/MANIFEST.MF file from my Spring Boot web app (contained in a jar file).

I'm trying the following code:

```
        InputStream is = getClass().getResourceAsStream("/META-INF/MANIFEST.MF");

        Properties prop = new Properties();
        prop.load( is );

```

But apparently there is something behind the scenes in Spring Boot that a different manifest.mf is loaded (and not my own located in META-INF folder).

Does anyone know how I can read my manifest app in my Spring Boot app?

**UPDATE:** After some research I noticed that using the usual way to read a manifest.mf file, in a Spring Boot application this is the Jar that is being accessed

```
org.springframework.boot.loader.jar.JarFile

```

Answer: 
Pretty much all jar files come with a manifest file, so your code is returning the ***first* file** it can find **in the classpath**.

Why would you want the manifest anyway? It's a file used by Java. Put any custom values you need somewhere else, like in a `.properties` file next to you `.class` file.

**Update 2**

As mentioned in a comment below, *not* in the question, the real goal is the version information from the manifest. Java already supplies that information with the [`java.lang.Package`](http://docs.oracle.com/javase/7/docs/api/java/lang/Package.html) class.

Don't try to read the manifest yourself, even if you could find it.

**Update 1**

Note that the manifest file is *not* a `Properties` file. It's structure is much more complex than that.

See the example in the java documentation of the [JAR File Specification](http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#Signature_Validation).

```none
Manifest-Version: 1.0
Created-By: 1.7.0 (Sun Microsystems Inc.)

Name: common/class1.class
SHA-256-Digest: (base64 representation of SHA-256 digest)

Name: common/class2.class
SHA1-Digest: (base64 representation of SHA1 digest)
SHA-256-Digest: (base64 representation of SHA-256 digest)

```

As you can see, `Name` and `SHA-256-Digest` occurs more than once. The `Properties` class cannot handle that, since it's just a `Map` and the keys have to be unique.
After testing and searching on Spring docs, I found a way to read the manifest file.

First off, Spring Boot implements its own ClassLoader that changes the way how resources are loaded. When you call `getResource()`, Spring Boot will load the first resource that matches the given resource name in the list of all JARs available in the class path, and your app jar is not the first choice. 

So, when issuing a command like:

```
getClassLoader().getResourceAsStream("/META-INF/MANIFEST.MF");

```

The first MANIFEST.MF file found in any Jar of the Class Path is returned. In my case, it came from a JDK jar library.

**SOLUTION:**

I managed to get a list of all Jars loaded by the app that contains the resource "/META-INF/MANIFEST.MF" and checked if the resource came from my application jar. If so, read its MANIFEST.MF file and return to the app, like that:

```
private Manifest getManifest() {
    // get the full name of the application manifest file
    String appManifestFileName = this.getClass().getProtectionDomain().getCodeSource().getLocation().toString() + JarFile.MANIFEST_NAME;

    Enumeration resEnum;
    try {
        // get a list of all manifest files found in the jars loaded by the app
        resEnum = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME);
        while (resEnum.hasMoreElements()) {
            try {
                URL url = (URL)resEnum.nextElement();
                // is the app manifest file?
                if (url.toString().equals(appManifestFileName)) {
                    // open the manifest
                    InputStream is = url.openStream();
                    if (is != null) {
                        // read the manifest and return it to the application
                        Manifest manifest = new Manifest(is);
                        return manifest;
                    }
                }
            }
            catch (Exception e) {
                // Silently ignore wrong manifests on classpath?
            }
        }
    } catch (IOException e1) {
        // Silently ignore wrong manifests on classpath?
    }
    return null;
}

```

This method will return all data from a manifest.mf file inside a Manifest object.

I borrowed part of the solution from [reading MANIFEST.MF file from jar file using JAVA](https://stackoverflow.com/questions/3777055/reading-manifest-mf-file-from-jar-file-using-java/3777116?s=1|0.3407#3777116)