我正在尝试使用 JettyWebAppProvider
来监视 WAR 的目录并部署它们。一切似乎都运行良好:Jetty 报告说它正在将 WAR 部署到我期望的上下文中。但是当我尝试访问该页面时,Jetty 在那里找不到任何东西。
我的服务器代码是
public static void main(String[] args) throws Exception {
Server httpServer = new Server(3030);
DeploymentManager deploymentManager = new DeploymentManager();
httpServer.setDumpBeforeStop(true);
ContextHandlerCollection contextHandlerCollection = new ContextHandlerCollection();
contextHandlerCollection.setServer(httpServer);
deploymentManager.setContexts(contextHandlerCollection);
WebAppProvider appProvider = new WebAppProvider();
appProvider.setMonitoredDirName("/tmp/wars/");
appProvider.setScanInterval(1);
appProvider.setDeploymentManager(deploymentManager);
appProvider.setExtractWars(true);
httpServer.addBean(deploymentManager);
httpServer.addBean(contextHandlerCollection);
httpServer.addBean(appProvider);
httpServer.start();
}
如果我使用 jetty-runner jar 并单独部署它们,我的 WAR 文件部署良好,但使用上面的代码,我看到如下输出:
2013-01-16 15:34:30.571:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/sample,file:/private/var/folders/qg/1t5k32g9567cwwl7y6tfdhj40000gn/T/jetty-0.0.0.0-3030-sample.war-_sample-any-/webapp/},/private/tmp/wars/sample.war
2013-01-16 15:34:30.571:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/sample,file:/private/var/folders/qg/1t5k32g9567cwwl7y6tfdhj40000gn/T/jetty-0.0.0.0-3030-sample.war-_sample-any-/webapp/},/private/tmp/wars/sample.war
2013-01-16 15:34:30.571:DBUG:oejuc.AbstractLifeCycle:starting HelloServlet
(有更多调试文本表明我的 webapp 已启动并位于/sample
)
当我访问时127.0.0.1:3030/sample
(我将服务器放在端口 3030),我收到一条 404 消息,并且 Jetty 记录
2013-01-16 15:34:47.799:DBUG:oejs.Server:REQUEST /sample on AsyncHttpConnection@63ce0072,g=HttpGenerator{s=0,h=-1,b=-1,c=-1},p=HttpParser{s=-5,l=10,c=0},r=1
2013-01-16 15:34:47.799:DBUG:oejs.Server:RESPONSE /sample 200 handled=false
我无法弄清楚我错过了什么。有没有人有这种设置的工作示例?