[英]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.