title: How to make Jersey work with Dagger dependency injection?
body: <p>Jersey normally uses HK2 dependency injection, but I would like to use Jersey with Dagger 2. Both Dagger and HK2 implement JSR 330, which I have taken as evidence that this should be possible without too much effort. I found ways to make Jersey work with CDI (e.g. Weld), Spring DI and Guice, but I can't find anything on Dagger.</p>
  
  <p>To provide some context: I'm running a Grizzly–Jersey server in an SE environment, not in an EE container. My Maven project has <code>com.google.dagger:dagger</code> and <code>org.glassfish.jersey.containers:jersey-container-grizzly2-http</code> as dependencies, but <em>not</em> <code>org.glassfish.jersey.inject:jersey-hk2</code>, since I want to replace HK2 with Dagger.</p>
  
  <p>The resource classes look like this:</p>
  
  <pre><code>@Path("/example")
  public final class ExampleResource {
  
      private final Dependency dependency;
  
      @Inject
      public ExampleResource(final Dependency dependency) {
          this.dependency = Objects.requireNonNull(dependency);
      }
  
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      public Example getExample() {
          return this.dependency.giveExample();
      }
  
  }
  </code></pre>
  
  <p>And the Dagger component could e.g. be defined as follows:</p>
  
  <pre><code>@Component
  public interface Application {
  
      public ExampleResource exampleEndpoint();
      public XyzResource xyzEndpoint();
      // etc.
  
  }
  </code></pre>
  
  <p>So that the main method would look similar to:</p>
  
  <pre><code>public final class Main {
  
      public static void main(final String[] args) {
          final Application application = DaggerApplication.create();
          final URI baseUri = UriBuilder.fromUri("http://0.0.0.0/").port(80).build();
          final ResourceConfig resourceConfig = new ResourceConfig();
          // how to initialize `resourceConfig` using `application`?
          final HttpServer httpServer = GrizzlyHttpServerFactory
                  .createHttpServer(baseUri, resourceConfig, false);
          try {
              httpServer.start();
          } catch (final IOException ex) {
              ...
          }
      }
  
  }
  </code></pre>
  
  <p>Running the application immediately results in an exception: <code>IllegalStateException: InjectionManagerFactory not found.</code> It seems that a Dagger implementation of this factory is needed.</p>
  
  <p>My question is: <strong>how to integrate Dagger with Jersey?</strong></p>