Serving Static Content Using Grizzly StaticHttpHandler from Inside .jar

I want Grizzly to serve static files from a .jar that contains a JAX-RS application, Grizzly and all other libraries. I use org.glassfish.grizzly.http.server.StaticHttpHandler to serve static files.

 public class Main { // ... public static void main(String[] args) throws IOException, URISyntaxException { final HttpServer server = startServer(); server.getServerConfiguration().addHttpHandler( new StaticHttpHandler(getTemplatePath()), "/static"); System.in.read(); server.stop(); } private static String getTemplatePath() throws URISyntaxException { return Main.class.getClassLoader().getResource("templates/static").getPath(); } } 

But it only works if I run the application with my IDE. If I pack .jar and run it, static files will not be found.

Is it possible to serve static files from .jar with grizzly StaticHttpHandler ? And How?

+6
source share
1 answer

You should use CLStaticHttpHandler instead of StaticHttpHandler .

Please take a look at this html server grizzly + jersey question (.html from the .jar archive)

+7
source

Source: https://habr.com/ru/post/946681/


All Articles