Multiple webroot folders with Jetty

Posted by Lóránt Pintér on Stack Overflow See other posts from Stack Overflow or by Lóránt Pintér
Published on 2010-03-08T21:49:55Z Indexed on 2010/03/08 21:51 UTC
Read the original article Hit count: 210

Filed under:
|

I'm using Jetty (version 6.1.22) to service a Java web application. I would like to make Jetty look in two different folders for web resources. Take this layout:

+- project1
|   +- src
|       +- main
|           +- webapp
|               +- first.jsp
|
+- project2
    +- src
        +- main
            +- webapp
                +- second.jsp

I would like to make Jetty serve both URLs:

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

I tried starting Jetty like this:

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

But it only serves first.jsp, and it returns 404 for second.jsp.

How can I get this to work?

© Stack Overflow or respective owner

Related posts about java

Related posts about jetty