title: Integration of embedded jetty with Resteasy
body: <p>I am trying to setup a jetty server which should:</p>
  
  <ol>
  <li>Serve html files on one context.</li>
  <li>Server REST API calls made using RestEasy on another context.</li>
  </ol>
  
  <p>I have referred <a href="https://stackoverflow.com/questions/10082055/integrating-jetty-with-resteasy">Integrating Jetty with RESTEasy</a> to integrate Resteasy and it works.
  I am able to configure jetty to serve html pages.
  But i am not able to combine both. </p>
  
  <p>I am using XML IoC format to configure jetty.
  The jetty.xml used to configure jetty server is as follows:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"&gt;
  
  &lt;Configure id="Server" class="org.eclipse.jetty.server.Server"&gt;
  
  
  
      &lt;Get name="ThreadPool"&gt;
        &lt;Set name="minThreads" type="int"&gt;&lt;Property name="jetty.threadPool.minThreads" deprecated="threads.min" default="10"/&gt;&lt;/Set&gt;
        &lt;Set name="maxThreads" type="int"&gt;&lt;Property name="jetty.threadPool.maxThreads" deprecated="threads.max" default="200"/&gt;&lt;/Set&gt;
        &lt;Set name="idleTimeout" type="int"&gt;&lt;Property name="jetty.threadPool.idleTimeout" deprecated="threads.timeout" default="60000"/&gt;&lt;/Set&gt;
        &lt;Set name="detailedDump"&gt;false&lt;/Set&gt;
      &lt;/Get&gt;
  
  
  
  
      &lt;Set name="handler"&gt;
        &lt;New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection"&gt;
          &lt;Set name="handlers"&gt;
           &lt;Array type="org.eclipse.jetty.server.Handler"&gt;
            &lt;Item&gt;
                &lt;New class="org.eclipse.jetty.server.handler.ContextHandler"&gt;
                    &lt;Set name="contextPath"&gt;/home&lt;/Set&gt;
                    &lt;Set name="handler"&gt;
                        &lt;New class="org.eclipse.jetty.server.handler.ResourceHandler"&gt;
                            &lt;Set name="directoriesListed"&gt;false&lt;/Set&gt;
                            &lt;Set name="welcomeFiles"&gt;
                              &lt;Array type="String"&gt;
                                  &lt;Item&gt;index.html&lt;/Item&gt;
                              &lt;/Array&gt;
                             &lt;/Set&gt;
                            &lt;Set name="resourceBase"&gt;/opt/myapp/web&lt;/Set&gt;
                        &lt;/New&gt;
                    &lt;/Set&gt;
                &lt;/New&gt;
            &lt;/Item&gt;
  
            &lt;Item&gt;
               &lt;New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/&gt;
             &lt;/Item&gt;
           &lt;/Array&gt;
          &lt;/Set&gt;
        &lt;/New&gt;
      &lt;/Set&gt;
  
      &lt;Set name="stopAtShutdown"&gt;&lt;Property name="jetty.server.stopAtShutdown" default="true"/&gt;&lt;/Set&gt;
      &lt;Set name="stopTimeout"&gt;5000&lt;/Set&gt;
      &lt;Set name="dumpAfterStart"&gt;&lt;Property name="jetty.server.dumpAfterStart" deprecated="jetty.dump.start" default="false"/&gt;&lt;/Set&gt;
      &lt;Set name="dumpBeforeStop"&gt;&lt;Property name="jetty.server.dumpBeforeStop" deprecated="jetty.dump.stop" default="false"/&gt;&lt;/Set&gt;
  
  &lt;/Configure&gt;
  </code></pre>
  
  <p>And the web.xml is as follows:</p>
  
  <pre><code>&lt;web-app xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
     &lt;context-param&gt;
        &lt;param-name&gt;resteasy.scan&lt;/param-name&gt;
        &lt;param-value&gt;true&lt;/param-value&gt;
     &lt;/context-param&gt;
  
     &lt;context-param&gt;
      &lt;param-name&gt;resteasy.resources&lt;/param-name&gt;
      &lt;param-value&gt;webapp.Resource&lt;/param-value&gt;
     &lt;/context-param&gt;
      &lt;context-param&gt;
        &lt;param-name&gt;javax.ws.rs.core.Application&lt;/param-name&gt;
        &lt;param-value&gt;webapp.MyApplicationConfig&lt;/param-value&gt;
     &lt;/context-param&gt;
  
     &lt;!-- set this if you map the Resteasy servlet to something other than 
     &lt;context-param&gt;
        &lt;param-name&gt;resteasy.servlet.mapping.prefix&lt;/param-name&gt;
        &lt;param-value&gt;/resteasy&lt;/param-value&gt;
     &lt;/context-param&gt;
     --&gt;
     &lt;!-- if you are using Spring, Seam or EJB as your component model, remove the ResourceMethodSecurityInterceptor --&gt;
  
      &lt;context-param&gt;
        &lt;param-name&gt;resteasy.resource.method-interceptors&lt;/param-name&gt;
        &lt;param-value&gt;
           org.jboss.resteasy.core.ResourceMethodSecurityInterceptor
        &lt;/param-value&gt;
     &lt;/context-param&gt;
  
  
     &lt;listener&gt;
        &lt;listener-class&gt;org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap&lt;/listener-class&gt;
     &lt;/listener&gt;
  
    &lt;servlet&gt;
      &lt;servlet-name&gt;Resteasy&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
  
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Resteasy&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>And the function which starts the server is:</p>
  
  <pre><code>   public void start()
          {
  
             try
             {
                 String serverCfgFile = Utils.getIstatsHome() + jettyConfig;
                 File f = new File(serverCfgFile);
                 if (!f.exists())
                 {
                     throw new Exception("Jetty conf file " + serverCfgFile + " not found");
                 }
  
                 server = new Server(7070);
  
                 XmlConfiguration configuration = new XmlConfiguration(new FileInputStream(f));
                 configuration.configure(server);
                 server.start();
             }
       catch (Exception ex)
         {
             System.out.println("Exception while configuring Jetty Server" + ex);
             ex.printStackTrace();
  
         }
          } 
  </code></pre>
  
  <p>The code which is needed to setup resteasy with jetty is:</p>
  
  <pre><code>WebAppContext context = new WebAppContext();
  
  context.setDescriptor("/opt/myapp/WEB-INF/web.xml");
  context.setResourceBase("/opt/myapp/lib");
  context.setContextPath("/stats");
  context.setParentLoaderPriority(true);
  
  server.setHandler(context);
  </code></pre>
  
  <p>How i do modify this jetty.xml  to achieve what this code does through xml.
  I tried modifying jetty.xml like this:</p>
  
  <pre><code>   &lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"&gt;
  
  &lt;Configure id="Server" class="org.eclipse.jetty.server.Server"&gt;
  
  
  
      &lt;Get name="ThreadPool"&gt;
        &lt;Set name="minThreads" type="int"&gt;&lt;Property name="jetty.threadPool.minThreads" deprecated="threads.min" default="10"/&gt;&lt;/Set&gt;
        &lt;Set name="maxThreads" type="int"&gt;&lt;Property name="jetty.threadPool.maxThreads" deprecated="threads.max" default="200"/&gt;&lt;/Set&gt;
        &lt;Set name="idleTimeout" type="int"&gt;&lt;Property name="jetty.threadPool.idleTimeout" deprecated="threads.timeout" default="60000"/&gt;&lt;/Set&gt;
        &lt;Set name="detailedDump"&gt;false&lt;/Set&gt;
      &lt;/Get&gt;
  
  
  
  
      &lt;Set name="handler"&gt;
        &lt;New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection"&gt;
          &lt;Set name="handlers"&gt;
           &lt;Array type="org.eclipse.jetty.server.Handler"&gt;
            &lt;Item&gt;
                &lt;New class="org.eclipse.jetty.server.handler.ContextHandler"&gt;
                    &lt;Set name="contextPath"&gt;/home&lt;/Set&gt;
                    &lt;Set name="handler"&gt;
                        &lt;New class="org.eclipse.jetty.server.handler.ResourceHandler"&gt;
                            &lt;Set name="directoriesListed"&gt;false&lt;/Set&gt;
                            &lt;Set name="welcomeFiles"&gt;
                              &lt;Array type="String"&gt;
                                  &lt;Item&gt;index.html&lt;/Item&gt;
                              &lt;/Array&gt;
                             &lt;/Set&gt;
                            &lt;Set name="resourceBase"&gt;/opt/myapp/web&lt;/Set&gt;
                        &lt;/New&gt;
                    &lt;/Set&gt;
                &lt;/New&gt;
            &lt;/Item&gt;
            &lt;Item&gt;
  
                        &lt;New class="org.eclipse.jetty.webapp.WebAppContext"/&gt;
                          &lt;Set name="contextPath"&gt;/stats&lt;/Set&gt;
                          &lt;Set name="resourceBase"&gt;/opt/myapp/lib&lt;/Set&gt;
                          &lt;Set name="descriptor"&gt;/opt/myapp/WEB-INF/web.xml&lt;/Set&gt;
  
            &lt;/Item&gt;
            &lt;Item&gt;
               &lt;New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/&gt;
             &lt;/Item&gt;
           &lt;/Array&gt;
          &lt;/Set&gt;
        &lt;/New&gt;
      &lt;/Set&gt;
  
      &lt;Set name="stopAtShutdown"&gt;&lt;Property name="jetty.server.stopAtShutdown" default="true"/&gt;&lt;/Set&gt;
      &lt;Set name="stopTimeout"&gt;5000&lt;/Set&gt;
      &lt;Set name="dumpAfterStart"&gt;&lt;Property name="jetty.server.dumpAfterStart" deprecated="jetty.dump.start" default="false"/&gt;&lt;/Set&gt;
      &lt;Set name="dumpBeforeStop"&gt;&lt;Property name="jetty.server.dumpBeforeStop" deprecated="jetty.dump.stop" default="false"/&gt;&lt;/Set&gt;
  
  &lt;/Configure&gt;
  </code></pre>
  
  <p>But modifying jetty.xml this way results in java.lang.ArrayStoreException in jetty 
  There is no stack trace of the exception. Just java.lang.ArrayStoreException is seen in the logs.
  Can this be done or am i missing some thing here ? 
  Please help!</p>