title: How to configure embedded jetty to access Jersey resources?
body: <p>I'm trying to configure embedded jetty to talk to my Jersey resources but I can't figure out how to do it. I've tried a couple of different things but nothing seems to work. The jetty tutorials don't really handle how to do it with Jersey. Any code suggestions or links are greatly appreciated </p>
  
  <p>EDIT:</p>
  
  <pre><code> package pojo;
  
  import org.eclipse.jetty.server.Server;
  import org.eclipse.jetty.servlet.DefaultServlet;
  import org.eclipse.jetty.servlet.ServletContextHandler;
  import org.eclipse.jetty.servlet.ServletHolder;
  import org.glassfish.jersey.servlet.ServletContainer;
  
  public class Main {
  
      public static void main(String[] args) throws Exception {
          Server server = new Server(8112);
          ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
          context.setContextPath("/");
          server.setHandler(context);
          ServletHolder h = new ServletHolder(new ServletContainer());
          h.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
          h.setInitParameter("com.sun.jersey.config.property.packages", "resources");
          h.setInitOrder(1);
          context.addServlet(h, "/*");
          try
          {
              server.start();
              server.join();
          }
          catch (Throwable t)
          {
              t.printStackTrace(System.err);
          }
  </code></pre>
  
  <p>Trying to connect to this class:</p>
  
  <pre><code>package resources;
  
  
  import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.PathParam;
  import javax.ws.rs.core.Context;
  import javax.ws.rs.core.Request;
  import javax.ws.rs.core.UriInfo;
  
  import com.codahale.metrics.MetricRegistry;
  import com.codahale.metrics.Timer;
  
  
  import java.util.ArrayList;
  import java.util.List;
  
  import pojo.Party;
  
  @Path("/parties")
  public class AllPartiesResource {
  
      @Context
      UriInfo url;
  
      @Context
      Request request;
  
      String name;
  
      public static final Timer allTime = DBConnection.registry.timer(MetricRegistry.name("Timer","all-parties"));
  
      @GET
      @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
      public List&lt;Party&gt; getAllParties() throws Exception
      {
          final Timer.Context context=allTime.time(); //start the timer 
          List&lt;Party&gt; list = new ArrayList&lt;Party&gt;();
          DBConnection.readAllData();
          list.addAll(DBConnection.getPartyCollection().values());
          context.stop(); //stops timer 
          return list;
  
  //      ---&gt; code for Jackson
  //      String string; 
  //      DBConnection.readAllData();
  //      ObjectMapper jsonMapper = new ObjectMapper();
  //      string=jsonMapper.writeValueAsString(DBConnection.getPartyCollection());
  //      return string;
      }
  
      @GET
      @Path("count")
      @Produces(MediaType.TEXT_PLAIN)
      public String getPartyCount() throws Exception
      {
          DBConnection.readAllData();
          return String.valueOf(DBConnection.getPartyCollection().size());
      }
  
      @Path("{party}") //points to OnePartyResource.class
      public OnePartyResource getParty(@PathParam("party")String party)
      {
          name = party;
          return new OnePartyResource(url,request,party);
      }
  }
  </code></pre>