Mikhail Kopylov
Mikhail Kopylov

Reputation: 2078

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

Using maven get compiled *.war file, which contains:

- 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

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

Application.class.getResource( "" ).getFile() returns %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.

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

But I don't need WEB-INF, I need META-INF directory. How to get it?

Upvotes: 3

Views: 7880

Answers (1)

Dirk Lachowski
Dirk Lachowski

Reputation: 3151

You are mixing cases. Your META-INF contains a MANIFEST.MF but you are trying to open a resource stream on manifest.mf.

You will have to change

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

to

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

Upvotes: 5

Related Questions