Reputation: 5120
This should be fairly easy, but for some reason nearly everything I try just seems to hand out a 'not found' error when I hook it up to a web browser.
I've got a single static context, and for the ResourceBase I've got 'file:jar:/path/to/myjar!/.'... any ideas what I'm missing?
Upvotes: 7
Views: 1408
Reputation: 75456
Try to load the resource from classloader like this,
ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
classLoader = getClass().getClassLoader();
}
InputStream stream = classLoader.getResourceAsStream(name);
Your approach assumes absolute path and it may not be true when the server is deployed. The jar could be in another JAR (WAR) or a temporary directory.
Upvotes: 2