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?
You have to use CLStaticHttpHandler
instead of StaticHttpHandler
.
Please take a look at this question html server grizzly+jersey (.html from .jar archive)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With