views:

992

answers:

3

Hi.

I've managed to deploy a .war to the Jboss web container containing and read the pom.properties located under /META-INF/groupid-dir/artifactid-dir/

To access the file I've used the following code inside a JSP in the same war:

ServletContext servletContext = getServletConfig().getServletContext(); 
InputStream in = servletContext.getResourceAsStream("META-INF/maven/groupid-dir/artifactid-dir/pom.properties");

This works just fine. But I want to be able to dynamically read pom.propertes from ALL .war deployed in the container. Is this possible or do I only have access to the context for the one war holder my jsp?

-mb

A: 

Basically, your application is running on the same machine as the JBoss container, so accessing the files on the local filesystem should be possible, much in the same way you're accessing your own .properties file. I'm not familiar with anything that should prevent you from doing this.

If you want to access files within the war file, you'll need to use the java.util.zip package, as war files are of course normal zip files. Just a friendly reminder.

Yuval
A: 

You will likely have to do something tricky like go through the JBoss MBeans. I realize this is vague, but consider looking into that approach. Here is a link on how to get the MBean server from an application within JBoss (add http://) www.jboss.org/community/wiki/FindMBeanServer (Stackoverflow is preventing me from pasting a link). I would imagine that you could find the Jboss Web mbean, peel off all web application mbeans, then ask each one for its classloader, then proceed to do what you already mentioned.

Rich Taylor
A: 

I don't think that reading a zip or using a jboss mbean are the right way. I don't think it is tricky and you were on the right track by using ServletContext.getResourceAsStream.

You can probably use ServletContext.getResourcePaths, but several times it seems, to identify subdirectories groupid and artifactid. Something like

servletContext.getResourceAsStream(servletContext.getResourcePaths(
    (String) servletContext.getResourcePaths("/META-INF/maven/")
               .iterator().next())
  .iterator().next() + "pom.properties")

or

servletContext.getResourceAsStream(servletContext.getResourcePaths(
    (String) servletContext.getResourcePaths("/META-INF/maven/")
               .iterator().next())
  .iterator().next() + "pom.xml")

for pom.xml

evernat