Read Manifest file in Spring boot application

Viewed 5308

We are using Spring-boot to build micro-services. In my project set-up we have a common maven module named platform-boot with main class with annotation SpringBootApplication

If we want to create a new micro-service (say Service-1), we simply add a dependency of platform-boot module and provide the main-class path in pom.xml and we are good to go.

Problem is when I try to read Manifest.MF file of Service-1 by writing code in my 'main-class' in dependent module. It reads the Manifest.MF file of platform-boot.

Below is the code snippet of how I am reading Manifest.MF file in my main class.

MyMain.class.getProtectionDomain().getCodeSource().getLocation().getPath();
//Returns the path of MyMain.class which is nested jar

Please suggest a way to read the Manifest.MF file of Service-1.

PS: I want to read the Maifest.MF file to get Implementation-Version. Please suggest if any other way of getting it as well.

2 Answers

Hi could you please elaborate the need of reading your service-1manifest.mf ?

If you just want the service1 as a dependeny in your parent common module and should not conflict with your service1 bootable application , you can do generate two jars through the exec configuration in spring-boot-maven-plugin .

Related