在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屋!