简体   繁体   English

如何从* .war / META-INF / MANIFEST.MF文件中读取manifest.mf?

[英]How to read manifest.mf from *.war/META-INF/MANIFEST.MF file?

Using maven get compiled *.war file, which contains: 使用maven get编译* .war文件,其中包含:

- META-INF
- - MANIFEST.MF
- WEB-INF
- - classes
- - lib
- - web.xml

Using java.util.jar.Manifest I want to read the manifest file to get application version from there like in https://stackoverflow.com/a/21046257/1728511 使用java.util.jar.Manifest我想从那里读取清单文件以获取应用程序版本,如https://stackoverflow.com/a/21046257/1728511

But Application.class.getResourceAsStream("/META-INF/manifest.mf") returns null . Application.class.getResourceAsStream("/META-INF/manifest.mf")返回null

Application.class.getResource( "" ).getFile() returns %WAR%/WEB-INF/lib/javax.ws.rs-api-2.0.jar!/javax/ws/rs/core/ Application.class.getResource( "" ).getFile()返回%WAR%/WEB-INF/lib/javax.ws.rs-api-2.0.jar!/javax/ws/rs/core/

Using Spring, I've implemented ApplicationContextAware interface to get ApplicationContext instance. 使用Spring,我实现了ApplicationContextAware接口来获取ApplicationContext实例。

And applicationContext.getClassLoader().getResourceAsStream( "" ) returns %WAR%/WEB-INF/classes . applicationContext.getClassLoader().getResourceAsStream( "" )返回%WAR%/WEB-INF/classes

But I don't need WEB-INF , I need META-INF directory. 但我不需要WEB-INF ,我需要META-INF目录。 How to get it? 怎么弄?

You are mixing cases. 你是混合案件。 Your META-INF contains a MANIFEST.MF but you are trying to open a resource stream on manifest.mf . 您的META-INF包含一个MANIFEST.MF但您正在尝试在manifest.mf上打开资源流。

You will have to change 你必须改变

Application.class.getResourceAsStream("/META-INF/manifest.mf")

to

Application.class.getResourceAsStream("/META-INF/MANIFEST.MF")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 META-INF / MANIFEST.MF文件中的库依赖关系 - library dependencies in META-INF/MANIFEST.MF file 如何在Spring Boot应用程序中读取我的META-INF / MANIFEST.MF文件? - How to read my META-INF/MANIFEST.MF file in a Spring Boot app? 在unnamed.war中找不到META-INF / MANIFEST.MF文件 - META-INF/MANIFEST.MF file not found in unnamed.war Aws Lambda访问META-INF / MANIFEST.MF? - Aws Lambda access to META-INF/MANIFEST.MF? jar文件中缺少主要属性,MANIFEST.MF文件位于META-INF文件夹中 - Missing main attribute inside the jar file, the MANIFEST.MF file is located in META-INF folder 对于 JIMAGE 文件,什么相当于 JAR 文件 META-INF/MANIFEST.MF? - What is the equivalent to JAR file META-INF/MANIFEST.MF for a JIMAGE file? 为什么不能使用maven-war-plugin将密钥与“ WEB-INF / classes / META-INF / MANIFEST.MF”合并? - Why keys are not merged with “WEB-INF/classes/META-INF/MANIFEST.MF” using maven-war-plugin? 提取和重新创建的jar不支持“ META-INF / MANIFEST.MF”中的清单。 - Extracted and recreated jar does not honor manifest at `META-INF/MANIFEST.MF` WAR,manifest.mf和版本 - WAR, manifest.mf and version Java - 即使 MANIFEST.MF 文件位于 /META-INF 中,App.jar 中也没有主要清单属性 - Java - No Main Manifest Attribute, in App.jar error even though MANIFEST.MF file is in /META-INF
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM