【问题标题】:Using WebAppProvider in Jetty 8, Jetty deploys a WAR and then can't find it在Jetty 8中使用WebAppProvider,Jetty部署了WAR然后找不到
【发布时间】:2012-12-31 07:27:37
【问题描述】:

我正在尝试使用 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

我无法弄清楚我错过了什么。有没有人有这种设置的工作示例?

【问题讨论】:

    标签: web-applications jetty


    【解决方案1】:

    您正在使用 WebAppProvider,但没有将其附加到 DeploymentManager(至少不是正确的方式)

    示例用法: http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java?h=jetty-8

    删除:

    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-26
      • 2012-05-06
      • 1970-01-01
      • 2016-05-04
      • 1970-01-01
      • 1970-01-01
      • 2013-04-20
      相关资源
      最近更新 更多