1

I try to get Attributes out of MANIFEST.MF in my war file. I work with Spring-MVC. I modified the manifest file with the maven war plugin and added build numbers and build date.

Now i want to get those attributes from the manifest file. I searched a lot in the internet and on stackoverflow and found a lot of things. I tried almost everything and nothing works. Thats why i try to find help here now.

That is my code:

@RequestMapping(value="/infos",method = RequestMethod.GET)
@ResponseBody
public String getVersion(HttpServletRequest req) {
    String version = "";

    try {
        InputStream stream = this.getClass().getClassLoader().getResourceAsStream("META-INF/MANIFEST.MF");
        Manifest manifest = new Manifest(stream);

        Attributes attributes = manifest.getMainAttributes();
        version = attributes.getValue("Implementation-Version");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return version;
}

The location of my manifest file is the following: .war/META-INF/MANIFEST.MF

This is what i get when i look with the debugger in the attributes:

enter image description here

I get the wrong manifest file but i dont know how to get the right one. I thought it have something to do with the classloader...

Hannes
  • 491
  • 5
  • 21
  • It looks more like Spring boot than plain spring? – khmarbaise Jan 11 '18 at 17:52
  • I added actuator from boot but the project itself is spring mvc plain – Hannes Jan 11 '18 at 17:56
  • @Hannes : I'm facing the same issue. Have you got the solution? – Ravi Aug 05 '22 at 13:59
  • 1
    @Ravi : Sorry for the late answer. I got no solution yet. – Hannes Mar 01 '23 at 14:30
  • I see you have the HttpServletRequest, you are probably in a Controller, you can do something like this:`Resource resourceManifest = new ServletContextResource(req.getSession().getServletContext(), "/META-INF/MANIFEST.MF"); Manifest manifest = new Manifest(resourceManifest.getInputStream());` – fl4l Aug 18 '23 at 14:22
  • Another useful way, in particular if you don't have the ServletRequest, is here: https://stackoverflow.com/a/25700939/2186777 – fl4l Aug 18 '23 at 14:46

0 Answers0