title: How to load servlet on startup using Jersey 2.3 with embedded Jetty
body: <p>I am migrating my Jersey web application from Jersey 1.17.1 to 2.3.1, using Jetty 9.0.6. With Jersey 1.17.1, the Resource would load during startup. However, pretty much the same code (below) only starts when a request comes in. But I would like to make sure it is loaded during startup (i.e., the constructor of the annotated resource class is called). Any idea what's wrong?</p>
  
  <pre><code>public static void startServer(){
      org.eclipse.jetty.server.Server server = new Server();
      org.eclipse.jetty.servlet.ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
      context.setContextPath("/");
      server.setHandler(context);
      org.glassfish.jersey.servlet.ServletContainer servletContainer = new ServletContainer();
      org.eclipse.jetty.servlet.ServletHolder servletHolder = new ServletHolder(servletContainer);
      servletHolder.setInitParameter(ServerProperties.PROVIDER_PACKAGES, "mypackage");
      servletHolder.setInitOrder(0);  // this does not seem to work
      context.addServlet(servletHolder, "/*");
      server.start();
  }
  </code></pre>
  
  <p>And roughly:</p>
  
  <pre><code>package mypackage;
  
  @Singleton
  @Path("/foo")
  public class MyResource {
  
      public MyResource(){
          // I want this to be called when I start the server
      }
  
      @Path("bar")
      public Response receivePayload(@Context HttpServletRequest request, String payloadString){
          // do some stuff
          return response;
      }
  }
  </code></pre>