I need to read the manifest file from java code. The project is a enterprise java project which runs in wildfly. I need to read the manifest file of web. Following is what i tried.
@Resource
private WebServiceContext context;
ServletContext servletContext =
(ServletContext) context.getMessageContext().get(
MessageContext.SERVLET_CONTEXT);
Properties prop = new Properties();
prop.load(servletContext.getResourceAsStream("/META-INF/MANIFEST.MF"));
But i get the following error
Caused by: javax.naming.NameNotFoundException: env/abc.def.rest.ManifestRestService/context -- service jboss.naming.context.java.module.abc-ear.abc-web.env."abc.def.ManifestRestService".context
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:104) [jboss-as-naming.jar:7.2.0.Final]
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:202) [jboss-as-naming.jar:7.2.0.Final]
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179) [jboss-as-naming.jar:7.2.0.Final]
at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:235)
Any ideas how to get this working.
I do not know if it is a proper way but I've managed to read manifest like this:
@WebListener
public class ManifestReader implements ServletContextListener {
...
@Override
public void contextInitialized(ServletContextEvent evt) {
ServletContext ctx = servletContextEvent.getServletContext();
InputStream is = ctx.getResourceAsStream("/META-INF/MANIFEST.MF");
...
}
}
This callback (contextInitialized
) is called at deployment time.
In our case ManifestReader
also processes requests (@Path("/blah")
, @RequestScoped
), so it has static field where read manifest is stored. If the field is not static, it is null by the time the request is processed.
I myself would like to know better way to do it.