【问题标题】:Multiple webroot folders with Jetty使用 Jetty 的多个 webroot 文件夹
【发布时间】:2010-03-08 21:49:55
【问题描述】:

我正在使用 Jetty(版本 6.1.22)为 Java Web 应用程序提供服务。我想让 Jetty 在两个不同的文件夹中查找网络资源。采用这种布局:

+- 项目1 | +- 源代码 | +- 主要 | +- 网络应用 | +- first.jsp | +- 项目2 +- 源代码 +- 主要 +- 网络应用 +- 第二个.jsp

我想让 Jetty 为这两个 URL 提供服务:

  • http://localhost/web/first.jsp
  • http://localhost/web/second.jsp

我尝试像这样启动 Jetty:

Server server = new Server();
SocketConnector connector = new SocketConnector();
connector.setPort(80);
server.setConnectors(new Connector[] { connector });

WebAppContext contextWeb1 = new WebAppContext();
contextWeb1.setContextPath("/web");
contextWeb1.setWar("project1/src/main/webapp");
server.addHandler(contextWeb1);

WebAppContext contextWeb2 = new WebAppContext();
contextWeb2.setContextPath("/web");
contextWeb2.setWar("project2/src/main/webapp");
server.addHandler(contextWeb2);

server.start();

但它只服务于first.jsp,它为second.jsp返回404。

我怎样才能让它工作?我也想留在相同的上下文中(即相同的 ClassLoader、相同的 SessionManager 等)。

【问题讨论】:

标签: java jetty


【解决方案1】:

从 6.1.12 开始,通过对 WebAppContext 的基础资源使用 ResourceCollection 来支持这一点:

Server server = new Server(80);
WebAppContext context = new WebAppContext();
context.setContextPath("/");
ResourceCollection resources = new ResourceCollection(new String[] {
    "project1/src/main/webapp", 
    "project2/src/main/webapp", 
});
context.setBaseResource(resources);
server.setHandler(context);
server.start();

更多信息:http://docs.codehaus.org/display/JETTY/Multiple+WebApp+Source+Directory

【讨论】:

    【解决方案2】:

    我相信您将不得不编写自己的 WebAppContext 子类来做您想做的事情。

    使用该上下文部署 Web 应用程序的最简单方法是使用上下文中的 XML 文件进行部署/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-11
      • 1970-01-01
      • 2011-08-29
      • 2010-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-22
      相关资源
      最近更新 更多