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中失败了?
发布于 2019-08-30 16:13:07
当您在IDE中运行它时,它不在jar中,并且您可以通过路径正常地访问文件系统上的资源。当您在jar中运行时,您需要访问jar文件中的资源。
为此,请使用ClassPathResourceManager。只要资源在类路径上,它也可以在jar外部工作。
https://stackoverflow.com/questions/57722926
复制相似问题