2

我想从 .jar 存档而不是文件夹中提供我的 .html 站点。目前我使用 grizzly(带球衣)并提供静态页面,例如:

HttpServer webServer;
....
....
webServer.getServerConfiguration().addHttpHandler(new StaticHttpHandler("varwww"), "/app");
webServer.start();

有没有办法让网络服务器不从文件夹“varwww”中检索 .html 并从 myhtml.jar 中获取它?

4

1 回答 1

3

此功能在 Grizzly 2.3.3+ 中实现。这是记者的问题

您可以使用特殊的 CLStaticHttpHandler 并传递 ClassLoader 以用于查找静态资源。例如:

httpServer.getServerConfiguration().addHttpHandler(
            new CLStaticHttpHandler(new URLClassLoader(new URL[] {new URL("file:///home/username/staticfiles.jar")})), "/www");

希望这会有所帮助。

于 2013-05-29T00:40:03.777 回答