2

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 APIs. 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

  1. Am I loading the MANIFEST file in a wrong way? Do I must use servletContext() to load the file?
  2. 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?
Samiron
  • 5,169
  • 2
  • 28
  • 55
  • When I just checked the manifest.mf files under my spring boot apps, I could understand most of them are in different locations in different apps. I also see 2 manifest.mf files with different contents in same app. – smilyface Jan 07 '19 at 13:34
  • Can you just check `find /path/to/your/springboot/app -type f | grep "MANIFEST\.MF"`. Please make sure there is only one manifest file. – smilyface Jan 07 '19 at 13:35
  • One another idea is to run your application as a jar `java -jar target/myapplication-0.0.1-SNAPSHOT.jar` so that you can make sure the manifest file which is bundled in the target is same you are trying to use. – smilyface Jan 07 '19 at 13:42
  • @smilyface I am working with war instead of jar. Do you still want me to check what you suggested? Regarding the find command, I already tried to list the available manifest files. So far I could find only one in the target folder. I can of course try the grep command as well. – Samiron Jan 07 '19 at 13:55
  • Yea, I forgot that it's war. Then I might be wrong ! By the time please go through https://stackoverflow.com/questions/1272648/reading-my-own-jars-manifest – smilyface Jan 07 '19 at 14:03

0 Answers0