在Jetty 8中使用WebAppProvider,Jetty部署了WAR,然后找不到它 [英] Using WebAppProvider in Jetty 8, Jetty deploys a WAR and then can't find it
问题描述
我正在尝试使用Jetty的WebAppProvider
监视WAR的目录并进行部署.一切似乎都运行良好:Jetty报告说它正在将WAR部署到我期望的上下文中.但是当我尝试访问该页面时,Jetty在此处找不到任何内容.
I'm trying to use Jetty's WebAppProvider
to watch a directory for WARs and deploy them. Everything seems to work fine: Jetty reports that it's deploying the WAR to the context I'd expect. But then when I try to visit the page, Jetty can't find anything there.
我的服务器代码是
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文件可以很好地部署,但是通过上面的代码,我看到这样的输出:
My WAR files deploy fine if I use the jetty-runner jar and deploy them individually, but with my above code I see output like this:
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
(还有更多调试文本指示我的Web应用程序已启动并且位于/sample
)
(there's lots more debug text indicating that my webapp is started and lives at /sample
)
当我访问127.0.0.1:3030/sample
(将服务器放置在端口3030上)时,我收到一条404消息和Jetty日志
When I visit 127.0.0.1:3030/sample
(I put the server at port 3030), I get a 404 message, and Jetty logs
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
我无法弄清我想念的是什么.有人有这种设置的可行示例吗?
I can't figure out what I'm missing. Does anyone have a working example of this sort of setup?
推荐答案
您正在使用WebAppProvider,但未将其附加到DeploymentManager(至少不是正确的方法)
You are using the WebAppProvider, but not attaching it to the DeploymentManager (at least not the right way)
用法示例: 删除:
appProvider.setDeploymentManager(deploymentManager);
在设置appProvider之后添加到某处:
Add somewhere after you setup the appProvider:
deploymentManager.addAppProvider(appProvider);
还需要向服务器添加处理程序:
Also you need to add a handler to the server:
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);
这篇关于在Jetty 8中使用WebAppProvider,Jetty部署了WAR,然后找不到它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!