I am loading a configfile using ClassLoader.getSystemResourceAsStream. The file is placed in the src folder of my GWT application. It ends up in war/WEB-INF/classes
.
I copy the war
folder to tomcat under webapps/MyApp
. When running the application, getSystemResourceAsStream throws an exception.
When running under Jetty it works fine.
Asked
Active
Viewed 3,615 times
3

Alex
- 32,506
- 16
- 106
- 171
3 Answers
3
Try:
getClass().getClassLoader().getResourceAsStream();
It will definitely work; I also had same type of problem. This question describes why you are having that problem.
-
Thanks... I am trying different solutions for more than 4 hours... this answer works for me... – Manan Shah Dec 12 '17 at 07:33
1
Try getClass().getResourceAsStream()
instead. You need to call this method to access the class loader for your web application. The method you're calling uses the system class loader, which I believe is only going to contain the classes for the web container itself.

WhiteFang34
- 70,765
- 18
- 106
- 111
-
ClassLoader.getResourceAsStream() is not a static method so I can not call it that way. – Alex May 10 '11 at 08:37
-
-
What happens? Does it work under Jetty? Perhaps you can include in your question the relevant lines of code. – WhiteFang34 May 10 '11 at 08:47
-
1
This should work:
Thread.currentThread().getContextClassLoader().getResourceAsStream( "relative/path" );
Note that relative/path is a path relative to war/WEB-INF/classes E.g. if your file is war/WEB-INF/classes/resources/my.properties then use "resources/my.properties"

Danilo Tommasina
- 1,740
- 11
- 25