Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Question regarding Embedded Jetty and WebApp Deployment

        Server server = new Server(80);
        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
        context.addServlet(new ServletHolder(new HelloServlet()),"/hello");
        ContextHandlerCollection contexts = new ContextHandlerCollection();
        WebAppContext webapp = new WebAppContext();

Don't use this with a webapp (the .setWar() a few lines below this does this for you, and correctly)

This is the same contextPath as your ServletContextHandler above, this will never work, as your ServletContextHandler will answer all requests, never letting your WebAppContext process anything.

Just skip the ServletContextHandler entirely.
Use webapp.addServlet() instead.
        contexts.setHandlers(new Handler[]{context, webapp});

If you have no ServletContextHandler, then you don't need the ContextHandlerCollection.

If you have no ContextHandlerCollection, you can just use server.setHandler(webapp)
The server starts up fine, the servlet handler is also registered fine, but my webapp Context startup always fails with the following exception
 2015-08-14 14:06:13.523:INFO:oejs.Server:OSGi Console: jetty-9.2.12.v20150709

Jetty 9.2.13.v20150730 is the current stable version of Jetty 9.2.x
2015-08-14 14:06:13.527:INFO:oejsh.ContextHandler:OSGi Console: Started o.e.j.s.ServletContextHandler@12aa6801{/,null,AVAILABLE}
2015-08-14 14:06:13.539:WARN:oejw.WebAppContext:OSGi Console: Failed startup of context o.e.j.w.WebAppContext@71922339{/,file:/E:/jettyTest/,null}{E:\jettyTest\
webapps\testWebApp.war} E:\jettyTest\org\eclipse\jetty\webapp\webdefault.xml (The system cannot find the path specified)

The change to not use .setResourceBase() should have made an improvement here.
- Joakim

Back to the top