tags:

views:

422

answers:

1

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?

+2  A: 

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.

ZZ Coder
I can readily change the path later, I'm just seeing if I can get this to work at all, and I'm not loading a servlet from the JAR -- just static .html files.
Don Werve
I don't think your syntax is right. It should be,jar:file:/path/to/my.jar!/package/fileIf this is on Windows, you might also need the drive letter.
ZZ Coder