title: OSGi: javax.annotation conflict: Java SE vs Java EE
body: <p>In a Java SE OSGi (Apache Felix) environment, I'm trying to integrate CDI using PAX CDI and Weld 2.2.6.Final.</p>
  <p>I'm currently getting the following error:</p>
  <pre><code>ERROR: Bundle org.jboss.weld.osgi-bundle [45] Error starting file:///someDir/org/jboss/weld/weld-osgi-bundle/2.2.6.Final/weld-osgi-bundle-2.2.6.Final.jar (org.osgi.framework.BundleException: Uses constraint violation. Unable to resolve bundle revision org.jboss.weld.osgi-bundle [45.0] because it is exposed to package 'javax.annotation' from bundle revisions org.jboss.spec.javax.annotation.jboss-annotations-api_1.2_spec [39.0] and org.apache.felix.framework [0] via two dependency chains.
  
  Chain 1:
    org.jboss.weld.osgi-bundle [45.0]
      import: (&amp;(osgi.wiring.package=javax.annotation)(version&gt;=1.1.0))
       |
      export: osgi.wiring.package=javax.annotation
    org.jboss.spec.javax.annotation.jboss-annotations-api_1.2_spec [39.0]
  
  Chain 2:
    org.jboss.weld.osgi-bundle [45.0]
      import: (&amp;(osgi.wiring.package=com.google.common.util.concurrent)(version&gt;=13.0.0))
       |
      export: osgi.wiring.package=com.google.common.util.concurrent; uses:=javax.annotation
    com.google.guava [1.0]
      import: (osgi.wiring.package=javax.annotation)
       |
      export: osgi.wiring.package=javax.annotation
    org.apache.felix.framework [0])
  </code></pre>
  <p>I think it's because Java SE (v8) already defines a package &quot;javax.annotation&quot; but Java EE (v7) specifies the same package with more annotations.</p>
  <p>&quot;javax.annotation&quot;, however, is exported already as a system package by the system bundle (org.apache.felix:org.apache.felix.framework:jar:4.2.1).</p>
  <p>What is the correct way in this case to make OSGi pick the one from Java EE instead?</p>
  <p><strong>Edit</strong></p>
  <ol>
  <li><p><strong>only add the system packages that are truly necessary from the JDK</strong></p>
  <p>This is not possible in this case as I'm writing a framework, not an application (<a href="https://www.drombler.org/drombler-fx" rel="nofollow noreferrer">Drombler FX</a>).</p>
  </li>
  <li><p><strong>Exclude javax.annotations from the org.osgi.framework.system.packages system property in default.properties</strong></p>
  <p>Actually, I've tried that already as I have a copy of default.properties in the framework anyway. It worked, but it seems more like a hack and increases the maintenance work when I need to upgrade this file. Also if ever the Maven Bundle Plugin checks the exported packages at compile time (which I would welcome), the people would have to start adding additional dependencies to their project when they want to use javax.annotations as that package would be exported by the system packages anymore.
  I was hoping to find a better solution.</p>
  </li>
  <li><p><strong>Use the endorsed mechansim</strong></p>
  <p>This looked like the cleanest solution so far, but I still hoped I could avoid that, since it increases the application packaging complexity.</p>
  </li>
  </ol>
  <p>Now, I just checked the Java SE 8 documentation and was surprised that JSR 250 is not listed as an endorsed technology anymore!??? It was listed as an endorsed technology in Java SE 7. Did they really remove the endorsed support for JSR 250 in Java SE 8 or is the documentation incorrect?</p>
  <p>Java SE 8: <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/standards/" rel="nofollow noreferrer">https://docs.oracle.com/javase/8/docs/technotes/guides/standards/</a></p>
  <p>Java SE 7: <a href="https://docs.oracle.com/javase/7/docs/technotes/guides/standards/" rel="nofollow noreferrer">https://docs.oracle.com/javase/7/docs/technotes/guides/standards/</a></p>
  <p>If it is still supported in Java SE 8, what do you think about this approach?</p>
  <p>Any other approaches?</p>