title: Embedded Jetty REST service with Welcome File
body: <p>I'm trying to create a web service that has a REST API and can serve documents such as static html. At the moment I've got the REST (Jersey 2.17) api working fine but I'm struggling to serve up resources such as my index.html</p>
  
  <p><strong>Project Structure</strong></p>
  
  <pre><code>src
  --main
  ----java
  ------resource
  --------RestResource.java
  ------app
  --------LocalRunner.java
  ----webapp
  ------index.html
  </code></pre>
  
  <p><strong>LocalRunner.java</strong></p>
  
  <pre><code>public class LocalRunner {
      private final Server server;
  
      public LocalRunner() {
          server = new Server(8315);
      }
  
      public void start() throws Exception {    
          // REST
          WebAppContext restHandler = new WebAppContext();
  
          restHandler.setResourceBase("./");
          restHandler.setClassLoader(Thread.currentThread().getContextClassLoader());
  
          ServletHolder restServlet = restHandler.addServlet(ServletContainer.class,  "/rest/*");
          restServlet.setInitOrder(0);
          restServlet.setInitParameter(ServerProperties.PROVIDER_PACKAGES, "resource");
  
          // Web
          ResourceHandler webHandler = new ResourceHandler();
          webHandler.setResourceBase("./");
          webHandler.setWelcomeFiles(new String[]{"index.html"});
  
          // Server
          HandlerCollection handlers = new HandlerCollection();
          handlers.addHandler(restHandler);
          handlers.addHandler(webHandler);
  
          server.setHandler(handlers);
          server.start();
      }
  
      public static void main(String[] args) throws Exception {
          new LocalRunner().start();
      }
  }
  </code></pre>
  
  <p>Hitting <code>localhost:8315/rest/someRestEndpoint</code> works fine but if I try hit just <code>localhost:8315</code> I get a directory structure when I'm expecting my <code>index.html</code> welcome file. What am I doing wrong? </p>
  
  <p><em>Note I am not using a WEB.XML as I'm trying to do all the configuration in the class above</em>.</p>
  
  <hr>
  
  <p><strong>Dependencies if it helps (Gradle)</strong></p>
  
  <pre><code>def jettyVersion = '7.2.2.v20101205';
  compile "org.eclipse.jetty:jetty-server:${jettyVersion}"
  compile "org.eclipse.jetty:jetty-webapp:${jettyVersion}"
  compile "org.eclipse.jetty:jetty-servlet:${jettyVersion}"
  
  def jerseyVersion = '2.17'
  compile "org.glassfish.jersey.core:jersey-server:${jerseyVersion}"
  compile "org.glassfish.jersey.containers:jersey-container-servlet-core:${jerseyVersion}"
  </code></pre>