Serving static content

If you just want to serve simple static content without needing to have an entire web application, there are a couple of alternatives.

Using a Servlet Context and DefaultServlet

You would choose this method of serving static content if you want to be able to use Servlets and/or take advantage of the other features of the DefaultServlet, such as file caching. The DefaultServlet is normally configured in the webdefault.xml file.

<Configure class="org.mortbay.jetty.servlet.Context">
  <Set name="contextPath">/javadoc</Set>
  <Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/javadoc/</Set>
  <Call name="addServlet">

The Context is used to match urls of the form /javadoc/*, and to set up the location of the static resources, which in this case is the directory $JETTY-HOME/javadoc. The DefaultServlet serves the resources.

Using a ContextHandler and a ResourceHandler

Alternatively, for a slightly more lightweight and simple solution you can use a ContextHandler and a ResourceHandler. There is an example of doing this in the jetty distribution in the $JETTY-HOME/contexts/javadoc.xml file.

<Configure class="org.mortbay.jetty.handler.ContextHandler">
   <Set name="contextPath">/javadoc</Set>
   <Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/javadoc</Set>
   <Call name="addHandler">
           <New class="org.mortbay.jetty.handler.ResourceHandler"/>

The ContextHandler is used to match urls of the form /javadoc/*, and to set up the location of the static resources (again $JETTY-HOME/javadoc). The ResourceHandler serves the resources.