I am working on a multi module Java Spring boot application. The structure looks like below.
module 1 (packaging: pom)
submodule 1.1 (packaging: jar)
submodule 1.2 (packaging: jar)
module 2 (packaging: pom)
submodule 2.1 (packaging: jar)
submodule 2.2 (packaging: jar)
webapplication (packaging: war)
use submodule jars as dependencies
The webapplication
module contains all the REST API
s. One of the REST API is supposed to read the MANIFEST.MF
file inside the war
file and provide some information related to the deployed application.
Following code is being used to read the MANIFEST.MF
file. (hand crafted right here)
InputStream input = getClass().getClassLoader().getResourceAsStream("META-INF/MANIFEST.MF");
Manifest manifest = new Manifest(input); //java.util.jar.Manifest
Attributes attrs = manifest.getMainAttributes();
Problem
When the application is run with spring-boot:run
command, the content I can find in attrs
is completely different than what I see in the MANIFEST.MF
file inside the war. It must be reading from some other manifest file.
Questions
- Am I loading the
MANIFEST
file in a wrong way? Do I must useservletContext()
to load the file? - Probably the above code is reading from the first jar file found in classpath. What is the best way to locate the manifest file of my deployed war file only? I am yet to try out
jcbi-manifests
package. Will it solve the problem?