如何在Spring Boot应用程序中读取我的META-INF / MANIFEST.MF文件? [英] How to read my META-INF/MANIFEST.MF file in a Spring Boot app?
问题描述
我正在尝试从我的Spring Boot网络应用程序(包含在jar文件中)中读取我的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).
我是尝试以下代码:
InputStream is = getClass().getResourceAsStream("/META-INF/MANIFEST.MF");
Properties prop = new Properties();
prop.load( is );
但是显然Spring Boot中有一些东西可以加载不同的manifest.mf(和不是我自己位于META-INF文件夹中。)
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).
有谁知道如何在Spring Boot应用程序中阅读我的清单应用程序?
Does anyone know how I can read my manifest app in my Spring Boot app?
更新:经过一番研究后,我注意到使用通常的方式读取manifest.mf文件,在Spring Boot应用程序中这是正在访问的Jar
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
推荐答案
我使用 java.lang.Package 从清单中读取spring boot中的 Implementation-Version
属性。
I use java.lang.Package to read the Implementation-Version
attribute in spring boot from the manifest.
String version = Application.class.getPackage().getImplementationVersion();
应配置 Implementation-Version
属性在 build.gradle
jar {
baseName = "my-app"
version = "0.0.1"
manifest {
attributes("Implementation-Version": version)
}
}
这篇关于如何在Spring Boot应用程序中读取我的META-INF / MANIFEST.MF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!