Over a million developers have joined DZone.

Minimal Jetty Http Server With Java Servlet

DZone's Guide to

Minimal Jetty Http Server With Java Servlet

· ·
Free Resource
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()), "/*");

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}