LaS*_*bra 21 jsp embeddedwebserver jar jetty embedded-jetty
我成功地将Jetty嵌入到测试应用程序中.它可以毫无问题地提供文件.现在我想知道Jetty是否可以提供其自己的Jar文件中的文件.
有谁知道这是否可能?
Uri*_*ter 38
Jetty嵌入页面上列出了一个示例:http://docs.codehaus.org/display/JETTY/Embedding+Jetty
诀窍是为类路径位置创建文件URL.
String webDir = this.class.getClassLoader().getResource("com/company/project/mywebdir").toExternalForm();
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
context.setResourceBase(webDir);
Run Code Online (Sandbox Code Playgroud)
如果你把Spring扔进这个等式,这很简单.它在这里:
...
WebAppContext webAppContext = new WebAppContext();
webAppContext.setServer(server);
webAppContext.setContextPath("/");
webAppContext.setResourceBase(new ClassPathResource("webapp").getURI().toString());
server.addHandler(webAppContext);
....
这将使jetty在jar文件中找到必要的Web资源.