Skip to content

Instantly share code, notes, and snippets.

@jmcshane
Created September 22, 2016 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmcshane/396c500613926cb808eb54bfac4122d1 to your computer and use it in GitHub Desktop.
Save jmcshane/396c500613926cb808eb54bfac4122d1 to your computer and use it in GitHub Desktop.
Endpoint to expose the manifest details of a jar or war file
@Controller
public class ManifestDetailsController {
private static final Logger logger = LoggerFactory.getLogger(ManifestDetailsController.class);
@RequestMapping(value="/getManifestDetails" ,method = RequestMethod.GET)
@ResponseBody
public Map<String,Object> getManifestDetails() {
Enumeration<URL> resource;
Map<String,Object> result = new HashMap<String,Object> ();
try {
resource = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME);
URL url = resource.nextElement();
InputStream is = url.openStream();
Manifest manifest = new Manifest(is);
Attributes mainAttributes = manifest.getMainAttributes();
for (Object key : mainAttributes.keySet()) {
result.put(key.toString(), mainAttributes.get(key));
}
}
catch (IOException e) {
logger.warn("Manifest details failed", e);
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment