• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getResourceAsStream using getClass() mehtod

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using some code that worked on Weblogic but not on Tomcat. This line returns null;

InputStream in = this.getClass().getResourceAsStream(this.pFileName);

where this.pFilenmae = /WEB-INF/XML-properties/XmlApiConstants.properties

This is just a class file and not a servlet or anything like that. I read something about it is probably a classpath issue but I do nto know how to fix it. I tried the followign as well...

* changing to this.pFilenmae = /WEB-INF/lib/XML-properties/XmlApiConstants.properties (Now under the lib directory)

* InputStream in = this.getClass().getClassLoader().getResourceAsStream(this.pFileName); (Adding getClassLoader method)

What can I do to fix this problem?
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
do you have access to the ServletContext ?

the getResourceAsStream method might be useful.

Otherwise, if you're using classloaders, take off the WEB-INF from the path.
 
I like tacos! And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic