• Post Reply Bookmark Topic Watch Topic
  • New Topic

File not found by getResourceAsStream  RSS feed

 
Douglas Kent
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm treading a path many have trodden before and written in this forum. Have looked at each of the postings and the many excellent replies, and tried them unsuccessfully. My situation is this: I have a package with a class that I do not want to have to modify to run under an EJB environment. It loads an XML file with a call to Class.getResourceAsStream(). I have run out of locations to place the XML file in to get it to load. (note-am running Sun Java System Enterprise Application Server 7) I have tried putting in the top level of the EJB jar file, the META-INF directory of the jar file, the root directory of the server, the lib directory of the server, in the same sub-directory as the class that is doing the call, which is below the lib directory. I should add that the code doing the call to getResourceAsStream is located in a jar file in the lib directory and is not being called directly from the bean class. I have seen the posting that discussed that doing direct java.io call is not advisable from the standpoint of fidelity to the spec, etc...
Here is the call, very simple:
Have used a direct java.io File call successfully to open a config file whose location was in the
ejb-jar.xml DD.
Any ideas welcome!
thanks
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!