3

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.

Alex
  • 32,506
  • 16
  • 106
  • 171

3 Answers3

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.

Community
  • 1
  • 1
Ankit
  • 2,753
  • 1
  • 19
  • 26
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
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