About     Search     Feed

Nilesh D Kapadia


Music     Twitter     Github

Using Embedded Jetty with a Spring web application

Running a Java web application (that would normally run in a servlet container) using embedded Jetty is pretty useful because it means you can run it in a debugger with hot code replace without needing a special app server launcher.

To do this, I downloaded Jetty and included the jars as described in this document in my classpath:

http://docs.codehaus.org/display/JETTY/Embedding+Jetty

Then I followed the instructions here that Sanjiv Jivan had wrote up, making modifications that were specific for my environment:

http://jroller.com/sjivan/entry/embedding_jetty_in_a_spring

I have a class that looks like this:

import org.springframework.context.support.FileSystemXmlApplicationContext;

public class JettyLauncher {
    public static void main(String[] args) throws Exception {
    	new FileSystemXmlApplicationContext("path/to/jetty.xml");
    }
}

I launch that class inside of Eclipse in debug mode using a saved debug/run configuration that includes the Jetty jar files (but I don’t have those jars in the main project classpath).

© 2017 Nilesh D Kapadia