【问题标题】:Static resources with undertow, from a fatjar带有undertow的静态资源,来自fatjar
【发布时间】:2020-01-03 11:35:30
【问题描述】:
private static HttpHandler createHandler(HttpHandler servletHandler) {
    return Handlers.path()
                   .addExactPath("/", resource(new PathResourceManager(Paths.get("src/main/resources/Index.html"), 100))
                           .setDirectoryListingEnabled(false)) // resolves index.html
                   .addPrefixPath(Context.getPath(), servletHandler)
                   .addPrefixPath("/static", resource(new PathResourceManager(Paths.get("src/main/resources/"))));

}

以上内容在我的 IDE 中有效,但在 fatjar 中失败?

【问题讨论】:

    标签: java servlets undertow


    【解决方案1】:

    当您在 IDE 中运行它时,它不在 jar 中,您可以通过路径正常访问文件系统上的资源。在 jar 中运行时,需要访问 jar 文件中的资源。

    为此使用ClassPathResourceManager。只要资源在类路径上,它也可以在 jar 之外工作。

    【讨论】:

    猜你喜欢
    • 2021-03-04
    • 1970-01-01
    • 2012-08-27
    • 1970-01-01
    • 2017-05-09
    • 1970-01-01
    • 2018-09-12
    • 2014-07-29
    • 1970-01-01
    相关资源
    最近更新 更多