Question

I want Grizzly to serve static files from within a .jar, which contains a JAX-RS application, Grizzly and all other libs. I'm using org.glassfish.grizzly.http.server.StaticHttpHandler to serve the 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 works only, if I start the application with my IDE. If I pack a .jar and run it, the static files are not found.

Is it possible to serve static files from within a .jar with grizzly's StaticHttpHandler? And how?

Was it helpful?

Solution

You have to use CLStaticHttpHandler instead of StaticHttpHandler.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top