title: Jetty Embedded, Jersey 2, Weld
body: <p>I'm using Jetty 9.1 and Jersey 2.5.1. Jersey has built-in support for Jetty, so I start my server like that:</p>
  
  <pre><code>public static void main(String[] args) {
  
      URI baseUri = UriBuilder.fromUri("http://localhost/").port(8080).build();
      ResourceConfig config = ResourceConfig.forApplicationClass(MyApplication.class);
  
      Server server = JettyHttpContainerFactory.createServer(baseUri, config);
  }
  </code></pre>
  
  <p>MyApplication simply calls <code>this.packages(...)</code> to lookup my REST api classes.</p>
  
  <p>However, the REST api class contains a <code>@Inject</code> annotated field, which should be injected by WELD. Obviously WELD is not started (CDI support not enabled), and weirder, it looks like HK2 (used by Jersey 2) is trying to perform the injection.</p>
  
  <p>(I have a <code>org.glassfish.hk2.api.UnsatisfiedDependencyException</code> when hitting the REST endpoint).</p>
  
  <p>How do I setup correctly WELD (preferably programmatically)?</p>