I am trying to load a resource that is contained in an embedded JAR file. In fact, the project is deployed to JBoss using an EAR file with the following structure:
deploy.ear
|
|-> project.sar
|
|-> sub_project.jar
| |
| |-> settings.xml
|
|-> com/path/project/
|
|-> main.class
Of main.javaI would like to get InputStreamfor settings.xml. What is the right way to do this?
My real understanding is that the following code should work, but it returns null:
this.getClass().getResourceAsStream("settings.xml");
Update
After some trial and error, the following operators work:
getClass().getResourceAsStream("/settings.xml");
getClass().getResourceAsStream("/sub_project.jar/settings.xml");
getClass().getClassLoader().getResourceAsStream("/settings.xml");
getClass().getClassLoader().getResourceAsStream("settings.xml");
getClass().getClassLoader().getResourceAsStream("sub_project.jar/settings.xml");
getClass().getClassLoader().getResourceAsStream("/sub_project.jar/settings.xml");
source
share