Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read my META-INF/MANIFEST.MF file in a Spring Boot app?

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
like image 321
Ricardo Memoria Avatar asked Aug 30 '15 06:08

Ricardo Memoria


People also ask

How do I open a manifest MF file?

The following screen snapshot demonstrates viewing the manifest file. This was easily brought up in NetBeans by simply using File --> Open File and selecting jdiff. jar to have it displayed as shown in the next screen snapshot. Other Java IDEs provide similarly easy-to-use viewing of manifest files within a JAR.

What is META-INF manifest MF?

The META-INF folder is the home for the MANIFEST. MF file. This file contains meta data about the contents of the JAR. For example, there is an entry called Main-Class that specifies the name of the Java class with the static main() for executable JAR files. Follow this answer to receive notifications.

Where is META-INF manifest MF?

The manifest file is named MANIFEST. MF and is located under the META-INF directory in the JAR. It's simply a list of key and value pairs, called headers or attributes, grouped into sections.

What is META-inf in spring boot?

META-INF is intended to contain the MANIFEST. MF file and the services subdirectory related to the ServiceLoader class, but other frameworks, including Spring, use it as well.


1 Answers

I use java.lang.Package to read the Implementation-Version attribute in spring boot from the manifest.

String version = Application.class.getPackage().getImplementationVersion();

The Implementation-Version attribute should be configured in build.gradle

jar {
    baseName = "my-app"
    version =  "0.0.1"
    manifest {
        attributes("Implementation-Version": version)
    }
}
like image 188
samsong8610 Avatar answered Sep 24 '22 13:09

samsong8610