java meta inf的读取,如何在Spring Boot应用程序中读取我的META-INF / MANIFEST.MF文件?...

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

解决方案

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)

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值