我正在制作一个嵌入Jetty Web服务器的Java应用程序,该服务器反过来提供使用Google Web Toolkit开发的内容。在Eclipse中运行时,它都工作正常,但是当我将它作为jar文件导出时,我得到的是一条Jetty错误消息,指出“未找到文件”。在java应用程序中嵌入jetty并将其导出为jar
码头服务器启动这样的:
WebAppContext handler = new WebAppContext();
handler.setResourceBase("./war");
handler.setDescriptor("./war/WEB-INF/web.xml");
handler.setContextPath("/");
handler.setParentLoaderPriority(true);
server.setHandler(handler);
try {
server.start();
server.join();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我怀疑问题是在handler.setResourceBase()和handler.setDescriptor()中使用的相对路径。我已经搜索并测试了很多解决方案,但目前为止无济于事。特别是我尝试使用类似getClass()。getResource(“./war”)toExternalForm(),但这只是抛出空例外。
我也试过:
ProtectionDomain protectionDomain = Start.class.getProtectionDomain();
URL location = protectionDomain.getCodeSource().getLocation();
但只导致码头服务Java类的目录列表。
有没有办法做到这一点?
如果你知道答案,请在这里更详细地描述它。提供一些提取物。该链接可能会过时... – 2013-06-20 07:53:56
@RadimKöhler这似乎是一个非问题,“如果你知道答案”部分不满足的链接。它甚至不会在嵌入式Jetty服务器中远程引用部署WAR。 – cklab 2013-07-10 22:21:38