javaspringjetty

Launch Jetty 9 Programmatically


Does someone know how to launch Jetty9 with a simple main in Java class??? For example, I've seen programs like:

public static void main(String[] args) throws Exception {
        Server server = new Server(8080);
        WebAppContext webAppContext = new WebAppContext("./src/main/webapp", "/recruiting");
        webAppContext.setLogUrlOnStart(true);
        webAppContext.setInitParameter(ContextLoader.CONTEXT_CLASS_PARAM, RecruitingAppContext.class.getName());
        webAppContext.addServlet(DispatcherServlet.class, "/");
        webAppContext.setWelcomeFiles(new String[]{"index.jsp"});
        webAppContext.addEventListener(new RequestContextListener());
        webAppContext.configure();

        server.setHandler(webAppContext);
        server.start();
        System.out.println("Server started");
        server.join();
    }

But I'm not yet able to run Jetty9 successfully. Anyway, I'm trying to do this with spring. Do someone let me see some examples in order to do this??? Thanks a lot :-)


Solution

  • I just documented one of our examples here a couple weeks back. We'll be documenting more of our examples and adding some as we get requests and as folks submit their own...

    anyway, this ought to get you going :)

    http://www.eclipse.org/jetty/documentation/current/embedded-examples.html#embedded-one-webapp


    The above link is now dead, but it was archived. The actual code in question is up on the Eclipse's Git (archived).