How to read MANIFEST.MF inside WAR application?

前端 未结 4 1512
执笔经年
执笔经年 2021-02-04 07:07

I would like to read MANIFEST.MF of my WAR application. How can I find its file name?

4条回答
  •  情歌与酒
    2021-02-04 07:53

    How can I find its file name?

    You already have it. Maybe you meant to find the absolute file location? You can use ServletContext#getRealPath() for this.

    String relativeWARPath = "/META-INF/MANIFEST.MF";
    String absoluteDiskPath = getServletContext().getRealPath(relativeWARPath);
    File file = new File(absoluteDiskPath);
    // ...
    

    Or if you want to get it as InputStream directly, use ServletContext#getResourceAsStream().

    InputStream input = getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF");
    // ...
    

提交回复
热议问题