我希望Grizzly从.jar中提供静态文件,其中包含JAX-RS应用程序,Grizzly和所有其他库。我正在使用org.glassfish.grizzly.http.server.StaticHttpHandler
来提供静态文件。
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();
}
}
但是只有我用IDE启动应用程序才有效。如果我打包.jar并运行它,则找不到静态文件。
是否可以使用grizzly StaticHttpHandler
从.jar中提供静态文件?怎么样?
答案 0 :(得分:7)
您必须使用CLStaticHttpHandler
代替StaticHttpHandler
。
请看一下这个问题 html server grizzly+jersey (.html from .jar archive)