Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch Jetty 9 Programmatically

Tags:

java

spring

jetty

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 :-)

like image 322
Fernando Aspiazu Avatar asked Jun 15 '13 14:06

Fernando Aspiazu


1 Answers

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

like image 195
jesse mcconnell Avatar answered Oct 16 '22 03:10

jesse mcconnell