Is there a way to load files stored inside JARs using getResourceAsStream
from Tomcat applications?
I have a library that puts all the files it needs inside its jar, along with the compiled classes. This code works when the library is used in standalone applications but not when the library is used inside Tomcat (using the PHP java-bridge).
final InputStream stream = Object.class.getResourceAsStream("/styles/foo.xsl");
I tried without success to use the solution outlined in question getResourceAsStream not loading resource in webapp and changed the code to
final ClassLoader resourceLoader = Thread.currentThread().getContextClassLoader();
final InputStream stream = resourceLoader.getResourceAsStream("/styles/foo.xsl");
The latter code does not work neither when the library is used standalone or when the library is used in Tomcat. In both cases stream == null
.
The file I am trying to load is correctly stored on the JAR in /styles/foo.xsl
. The JAR with all the classes and these other files is tomcat/webapps/iJavaBridge/WEB-INF/lib/
.
Can someone suggest a piece of code that works both in Tomcat and non-Tomcat applications?