2

I want to read MANIFEST.MF of my deployment unit which is a WAR file.

A typical way to do:

servletContext.getResource("/META-INF/MANIFEST.MF);

But how to do this if you have no reference to a ServletContext? For example in a job triggered by the Java EE TimerService? Or even if the application is not a webapp?

Any ideas?

roehrijn
  • 1,387
  • 1
  • 11
  • 20
  • possible duplicate of [How do I read the manifest file for a webapp running in apache tomcat?](http://stackoverflow.com/questions/615493/how-do-i-read-the-manifest-file-for-a-webapp-running-in-apache-tomcat) – AllTooSir Jun 12 '13 at 07:04
  • http://stackoverflow.com/questions/3777055/reading-manifest-mf-file-from-jar-file-using-java – AllTooSir Jun 12 '13 at 07:05
  • no it isn't a duplicate. Thread.currentThread().getContextClassLoader().getR...() reads from der Classloader Context which is not necessarily the deployment unit one's. – roehrijn Jun 12 '13 at 07:23
  • I have a similar requirement, I am using the Maven (buildnumber-maven-plugin) plugin to create a build id for a server application. I want to access the buildid from the MANIFEST.FM in the main start-up code and log the version, however, this code is running \@ApplicationScoped i.e. it's not possible to inject a ServletContext because its \@RequestScoped context is not active. I tried loading the MANIFEST.MF via a class loader but that returned a different manifest to the one belonging to my application. – mikee Apr 21 '20 at 14:33

0 Answers0