How To: Read web/META-INF/MANIFEST.MF in Web Application

Hi All, 

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:

//Build Info
ServletContext aContext= getServletContext();
InputStream fis =aContext.getResourceAsStream("/META-INF/MANIFEST.MF");

Hope this helps you 🙂 . Do post your comments

4 Replies to “How To: Read web/META-INF/MANIFEST.MF in Web Application”

  1. Решил добавить RSS и получать новости, мне лично понравилось, что написал автор

  2. Your post solved my problem 🙂

    Just to add for Spring 3.0:

    public class VersionController {
    public @ResponseBody
    Map getAppVersionData(HttpServletRequest req) throws IOException {
    Map map = new HashMap();

    ServletContext aContext = req.getSession().getServletContext();
    InputStream fis = aContext.getResourceAsStream(“/META-INF/MANIFEST.MF”);

    Properties p = new Properties();
    p.load( fis );

    . . .


  3. Thanks,
    This really works.
    I need to get PROJECT path.
    Actually I’m developing a html mail. I save my template in one location. when uploaded to server the path?

    try {
    ServletContext aContext = request.getServletContext();
    String fis = aContext.getRealPath("/");
    } catch (Exception e) {

  4. I got what i need from featuriz.
    hear is the code.

    try {
    ServletContext aContext = request.getServletContext();
    String fis = aContext.getResource("/").getPath().replaceAll("/WEB-INF/classes/", "");
    } catch (Exception e) {

Leave a Reply

Your email address will not be published. Required fields are marked *