The Loader.getSystemResourceAsStream class does not work when working on tomcat

I am loading a configuration file using ClassLoader.getSystemResourceAsStream. The file is placed in the src folder of my GWT application. It ends on war/WEB-INF/classes. I will copy the folder warto tomcat under webapps/MyApp. When the application starts, getSystemResourceAsStream throws an exception. When working under Jetty, it works great.

+3
source share
3 answers

Try:

getClass().getClassLoader().getResourceAsStream();

This will definitely work; I also had the same type of problem. This question describes why you have this problem.

+4
source
+1

This should work:

Thread.currentThread().getContextClassLoader().getResourceAsStream( "relative/path" );

Note that relative / path is the path relative to War / WEB-INF / classes For example. if your file is war / WEB-INF / classes / resources / my.properties then use "resources / my.properties"

+1
source

All Articles