title: Serving static files with embedded Jetty
body: <p>I'm trying to build a simple demo app with embedded Jetty that serves static files from a "html" directory that's a subdirectory of the current working directory.  The idea is that the directory with the demo jar and content can be moved to a new location and still work.</p>
  
  <p>I've tried variations of the following, but I keep getting 404s.</p>
  
  <pre><code>ServletContextHandler context = 
                         new ServletContextHandler(ServletContextHandler.SESSIONS);
  context.setContextPath("/");
  
  context.getInitParams().put(
                         "org.eclipse.jetty.servlet.Default.resourceBase", "html");
  context.addServlet(new ServletHolder(new DefaultServlet()), "/html");
  
  Server jetty = new Server(8080);
  jetty.setHandler(context);
  
  jetty.start();
  </code></pre>
  
  <p><strong>Update:</strong> Here's a solution as documented in the Jetty tutorial.  As mentioned in the correct answer, it uses a <code>ResourceHandler</code> instead of a <code>ServletContextHandler</code>:</p>
  
  <pre><code>    Server server = new Server();
      SelectChannelConnector connector = new SelectChannelConnector();
      connector.setPort(8080);
      server.addConnector(connector);
  
      ResourceHandler resource_handler = new ResourceHandler();
      resource_handler.setDirectoriesListed(true);
      resource_handler.setWelcomeFiles(new String[]{ "index.html" });
  
      resource_handler.setResourceBase(".");
  
      HandlerList handlers = new HandlerList();
      handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
      server.setHandler(handlers);
  
      server.start();
      server.join();
  </code></pre>