Serving static content from jarfile with Jetty?

This should be pretty easy, but for some reason, almost everything I try to do seems to throw a "not found" error when I connect it to a web browser.

I have one static context, and for ResourceBase I have a file: jar: / path / to / myjar! / .'... any ideas what I am missing?

+7
java jruby jetty
source share
1 answer

Try loading the resource from the loader class as follows:

ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = getClass().getClassLoader(); } InputStream stream = classLoader.getResourceAsStream(name); 

Your approach assumes an absolute path, and this may not be true when the server is deployed. The bank can be in another JAR (WAR) or a temporary directory.

+2
source share

All Articles