I am trying to read an own MANIFEST.MF resource in a Java servlet. My situation: I have a WAR (with the manifest I want to read) inside an EAR. There are several other WARs and JARs in the EAR. A class path is really long.
I tried several ways found in the Web, including StackOverflow.
I can read all MANIFEST.MF files using
this.getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
and iterate through them. However, I do not know which one is mine - I do not know even Implementation-Title since this is generated by a build pipe. (I can guess with knowledge of the build pipe, therefore I know the correct manifest is there. However, I cannot guess in a production code.)
Of course,
this.getClass().getClassLoader().getResourceAsStream("META-INF/MANIFEST.MF");
returns a completely wrong manifest from some other jar on a class path.
I also tried
this.getServletContext().getResourceAsStream("META-INF/MANIFEST.MF");
but it returns a null.
How to access a MANIFEST.MF file belonging to the WAR containing a currently running servlet?
I also tried
this.getServletContext().getResourceAsStream("META-INF/MANIFEST.MF");
but it returns a null.
That path must start with /
in order to represent an absolute WAR resource path.
this.getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF");
Using ClassLoader#getResourceXxx()
doesn't make sense as WAR's own manifest file isn't located in classpath. It's located in webroot, next to /WEB-INF
and all. Therefore, ServletContext#getResourceXxx()
is the only way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With