Access build number from MANIFEST


/ Published in: Java
Save to your folder(s)

How to access the build number in the WAR file (generated by the Maven build number plugin) from Java.


Copy this code and paste it in your HTML
  1. String appServerHome = getServletContext().getRealPath("/");
  2.  
  3. File manifestFile = new File(appServerHome, "META-INF/MANIFEST.MF");
  4.  
  5. Manifest mf = new Manifest();
  6. mf.read(new FileInputStream(manifestFile));
  7.  
  8. Attributes atts = mf.getMainAttributes();
  9.  
  10. System.out.println("Version: " + atts.getValue("Implementation-Version"));
  11. System.out.println("Build: " + atts.getValue("Implementation-Build"));

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.