Quick Start - Handlers
The following code implements an anonymous hello handler and starts a jetty server with it:
Quick Start - Servlets
Here is a simple example of embedding Jetty using a Hello world servlet:
Setting up the classpath
To run Jetty you need only the following jars on the classpath:
This gives you the capability to handle HTTP with handlers, servlets and webapplications.
Additional features such as JSP and AJP require additional jars (normally found in subdirectories of $JETTY_HOME/lib).
Java Server Pages
You need to use J2SE5 (aka jdk 1.5) if you wish to use JSP2.1.
This is the jsp version mandated by servlet specification 2.5. You will need these jars:
JSP 2.0 is used with version 2.4 of the servlet specification. Depending on the functionality you require, you may be able to use this version rather than the newer JSP2.1
These are the dependencies when JSP 2.0 is used:
The jetty configuration files (eg jetty.xml) have an xml syntax that is a straightforward mapping of the java API. Take a look at the files in etc/ for some hints on what calls to make in your own code. Here's the minimal code to set up a Jetty server and webapp:
For More Information
There are several examples of embedding Jetty in the distribution in the
examples/embedded directory. Also take a look at the Tutorial on Embedding Jetty.