DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Minimal Jetty Http Server With Java Servlet
This will start a Jetty http server with a single Java servlet at the root. See http://www.mortbay.org/ for Jetty downloads. This needs HelloWorldServlet from one of my other posts. Make life easier by downloading my ant build.xml as well.
package com.babblemind;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;
public class JettyLauncher {
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
Context root = new Context(server, "/", Context.SESSIONS);
root.addServlet(new ServletHolder(new HelloWorldServlet()), "/*");
server.start();
}
}





