我正在尝试使用Jetty的WebAppProvider
来查看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
我无法弄清楚我错过了什么。有没有人有这种设置的工作示例?
答案 0 :(得分:4)
您正在使用WebAppProvider,但未将其附加到DeploymentManager(至少不是正确的方式)
卸下:
appProvider.setDeploymentManager(deploymentManager);
在设置appProvider之后添加某处:
deploymentManager.addAppProvider(appProvider);
您还需要向服务器添加处理程序:
HandlerCollection handlers = new HandlerCollection();
RequestLogHandler requestLogHandler = new RequestLogHandler();
handlers.setHandlers(new Handler[] { contextHandlerCollection, new DefaultHandler(), requestLogHandler });
StatisticsHandler stats = new StatisticsHandler();
stats.setHandler(handlers);
httpServer.setHandler(stats);