Multiple folders of web courts with Jetty

I am using Jetty (version 6.1.22) to serve a Java web application. I would like Jetty to 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 Jetty to serve both URLs:

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

I tried to start Jetty as follows:

 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 make this work? I would also like to stay in the same context (e.g. same ClassLoader, same SessionManager, etc.).

+4
source share
2 answers

Starting with version 6.1.12, this is supported using the ResourceCollection for the underlying WebAppContext resource:

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

Additional information: http://docs.codehaus.org/display/JETTY/Multiple+WebApp+Source+Directory

+9
source

I believe that you will have to write your own subclass of WebAppContext, doing what you want to do.

The easiest way to deploy your web application with this context is to deploy using an XML file in contexts /

0
source

Source: https://habr.com/ru/post/1303503/


All Articles