【问题标题】:Serving static content with grizzly's StaticHttpHandler from within a .jar在 .jar 中使用 grizzly 的 StaticHttpHandler 提供静态内容
【发布时间】: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 中提供静态文件?怎么做?

【问题讨论】:

    标签: java jax-rs grizzly


    【解决方案1】:

    您必须使用CLStaticHttpHandler 而不是StaticHttpHandler

    请看一下这个问题 html server grizzly+jersey (.html from .jar archive)

    【讨论】:

    • 谢谢,但是在哪里可以找到 CLStaticHttpHandler?它不在 Grizzly 包中,甚至 Google 也只找到了 3 页。
    • 它带有 Grizzly 版本 2.3.3。更多细节可以在这里找到:mytecc.wordpress.com/2013/06/06/…
    • 好吧,我不是最新的,因为对于我来说,Grizzly 是来自 JAX-RS 的传递依赖。
    猜你喜欢
    • 2013-08-23
    • 1970-01-01
    • 2016-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-27
    • 2011-10-14
    • 2014-07-30
    相关资源
    最近更新 更多