我正在製作一個嵌入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