0
votes

I have a Java project deployed on Tomcat 8. I'm not using any framework.

If, during run-time, I run something like:

this.getClass().getClassLoader().getResourceAsStream("xyz");

This works if "xyz" is a file located in the WEB-INF/classes directory; however, the above line returns 'null' if the file "xyz" is located in the WEB-INF/lib directory.

Is there any way for me to read files in the WEB-INF/lib directory during run-time using the 'getResourceAsStream()' method of the 'ClassLoader' class?

1
The answer is no. WEB-INF/lib is not in the classpath. It is supposed to contain jar files, that are in the classpath. Why don't you just put the file under WEB-INF/classes?JB Nizet
Thing is you cant access files from lib folder, put you file in some other location. alternate solution is you have to out absolute path of file.KhAn SaAb
Thanks for the prompt answer guys. I was just making sure. (Now I know a little bit more about how Tomcat works.)Omer Hassan
@OmerHassan - you should add an answer to complete this question if no more opened questions.Minh Kieu

1 Answers

0
votes

The answer, as I've learned from the comments, is that Classloader.getResourceAsStream() cannot read from the WEB-INF/lib folder in Tomcat.