user1639616
user1639616

Reputation: 315

Load resource file outside jar

I have created a jar which contains a class that loads an external resource file from class path of my web application. My application is running on resin server. I have deployed my jar in web-inf/lib and my resource file is in web-inf/classes folder. Now the resource file is being accessed using

getClass().getResourceAsStream("/resource-name.json");

However, the application throws a null pointer exception when I run it. Could anyone explain to me why my class loader is not able to find this resource file located in web-inf/classes folder? I searched this forum but did not find anything like my problem here.

Like always, I appreciate your responses and thank you.

Upvotes: 0

Views: 877

Answers (1)

Crazyjavahacking
Crazyjavahacking

Reputation: 9697

To investigate, first try to print all locations where your ClassLoader tries to load classes/resources:

((URLClassLoader) getClass().getClassLoader()).getURLs();

assuming that the Resign's ClassLoader extends URLClassLoader. It should contain your folder.

Upvotes: 1

Related Questions