As you all know In web application inside web directory there is a META-INF directory. Inside which we have MANIFEST.MF that holds version information. I have to read the MANIFEST.MF from this directrory. Need the manifest info for the purpose of build info and have to show in footer of each page. It's easy to read it in case of JAR file and while searching on net I got mostly examples on jar,classpath related Manifest. But my requirement was to read web/META-INF/MANIFEST.MF file.
So I am posting here what I done:
Inside web application then using the ServletContext.getResourceAsStream
method should work and same I used.
// for a Servlet, you can get the ServletContext like this
ServletContext aContext = getServletConfig().getServletContext();
InputStream inputStream = aContext.getResourceAsStream("/META-INF/MANIFEST.MF");
In Spring application do following inside controller:
ServletContext aContext= getServletContext();
InputStream fis =aContext.getResourceAsStream("/META-INF/MANIFEST.MF");
Hope this helps you 🙂 . Do post your comments