【发布时间】:2013-06-02 11:26:07
【问题描述】:
我希望 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 中提供静态文件?怎么做?
【问题讨论】: