Create a simple HTTP server with Java?

Stefan Kendall picture Stefan Kendall · Apr 27, 2010 · Viewed 138.3k times · Source

What's the easiest way to create a simple HTTP server with Java? Are there any libraries in commons to facilitate this? I only need to respond to GET/POST, and I can't use an application server.

What's the easiest way to accomplish this?

Answer

Kris picture Kris · Apr 27, 2010

Use Jetty. Here's a tutorial for embedding Jetty. (Here's an outdated tutorial.)

Jetty is pretty lightweight, but it does provide a servlet container, which may contradict your requirement against using an "application server".

You can embed the Jetty server into your application. Jetty allows EITHER embedded OR servlet container options.