Is it possible to read the properties file from all .war files deployed in the JBoss container

I managed to install .war in a Jboss web container containing and read pom.properties located in the / META -INF / groupid-dir / artifactid-dir / directory

To access the file, I used the following code inside the JSP in the same war:

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

This works great. 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 one war owner? Jsp

-mb

+2
source share
5 answers

Basically, your application runs on the same computer as the JBoss container, so access to files on the local file system should be the same as access to your own .properties file. I am not familiar with anything that should prevent you from doing this.

If you want to access files in a military file, you will need to use the java.util.zip package, since war files are, of course, normal zip files. Just a friendly reminder.

0
source

You will probably have to do something complicated, how to get through JBoss MBeans. I understand that this is vague, but think about this approach. Here is a link on how to get an MBean server from an application in JBoss (add http: //) www.jboss.org/community/wiki/FindMBeanServer (Stackoverflow does not allow me to embed a link). I would suggest that you can find the Jboss Web mbean, clear all mbeans web applications, and then ask everyone for their class loader, and then proceed with what you already mentioned.

0
source

I don't think reading zip or using jboss mbean is the right way. I don't think this is complicated, and you were on the right track using ServletContext.getResourceAsStream .

You might be able to use ServletContext.getResourcePaths , but several times it seems to identify the groupid and artifactid subdirectories. Sort of

 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

0
source

If the WAR file exploded like a folder, you should be able to use

String basePath = getServletContext (). getRealPath ("/");

This approach may not work if the WAR file is in the archive.

0
source

You can only search for resources in your current class path. The usual operation of a web container is to create a specific class path for each deployed artifact without accessing other artifacts deployed in the container.

This is very important to avoid artifact A, which uses foo-1.0.jar, so as not to accidentally use foo-0.9.jar, which deploys with artifact B.

Therefore, you will need to contact the container for help. This, in turn, means that for this you need to write a specific container code. It will make you addicted to the provider β€” you may not want to.

0
source

Source: https://habr.com/ru/post/912848/


All Articles