I'm late, but you can try the following two methods
using these necessary classes
import java.util.jar.Attributes; import java.util.jar.Manifest;
These methods allow me to access the jar attributes. I like to be backward compatible and use the latter. So i used this
public Attributes detectClassBuildInfoAttributes(Class sourceClass) throws MalformedURLException, IOException { String className = sourceClass.getSimpleName() + ".class"; String classPath = sourceClass.getResource(className).toString(); if (!classPath.startsWith("jar")) { // Class not from JAR return null; } String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF"; Manifest manifest = new Manifest(new URL(manifestPath).openStream()); return manifest.getEntries().get("Build-Info"); } public String retrieveClassInfoAttribute(Class sourceClass, String attributeName) throws MalformedURLException, IOException { Attributes version_attr = detectClassBuildInfoAttributes(sourceClass); String attribute = version_attr.getValue(attributeName); return attribute; }
This works well when you use maven and you need detailed pom details for famous classes. Hope this helps.
GetBackerZ Oct 19 '17 at 13:54 on 2017-10-19 13:54
source share