title: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory in OSGi
body: <p>I'm trying to get the library <a href="https://github.com/biojava/biojava" rel="nofollow noreferrer">BioJava</a> to work inside an OSGi context. </p>
  
  <p>To get the JAR into the OSGi context, I'm using the Maven plugin <a href="https://github.com/reficio/p2-maven-plugin" rel="nofollow noreferrer">p2-maven-plugin</a>, which generates a file <em>Manifest.MF</em>, and the part relevant to the exception I'm facing is:</p>
  
  <pre><code>Bundle-SymbolicName: org.biojava.core
  Bundle-Version: 5.3.0
  Import-Package: [snip],
   org.slf4j;resolution:=optional,
   [snap]
  </code></pre>
  
  <p>Which looks okay to me. However when I access a class that uses slf4j I get the titular exception:</p>
  
  <pre><code>java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
      at org.biojava.nbio.core.sequence.template.AbstractCompoundSet.&lt;clinit&gt;(AbstractCompoundSet.java:40)
      at org.biojava.nbio.core.sequence.io.ABITrace.getSequence(ABITrace.java:179)
  Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory cannot be found by org.biojava.core_5.3.0
      at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:511)
      at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
      at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:414)
  </code></pre>
  
  <p>Now it's easy to find this exception everywhere, because a lot of people have tried (and failed) to install slf4j. I checked sites like <a href="http://www.slf4j.org/codes.html" rel="nofollow noreferrer">the documentation</a> or the SO question <a href="https://stackoverflow.com/questions/9030065/classnotfoundexception-org-slf4j-loggerfactory">ClassNotFoundException: org.slf4j.LoggerFactory</a> and hence tried to add the following bundles:</p>
  
  <ul>
  <li>slf4j-simple</li>
  <li>slf4j-log4j12 (plus the log4j dependencies)</li>
  <li>pax-logging-log4j2</li>
  </ul>
  
  <p>However neither worked. Maybe the OSGi container is having problems, but slf4j JARs have the bundle information with the export packages out of the box, so I'm assuming these work. And the BioJava JAR has an import package, so I have no idea why it wouldn't be able to find the class.</p>
  
  <p>Oh, I checked, the <code>LoggerFactory</code> is present in slf4j-api, so it's not that, either.</p>
  
  <p>I also tried different start levels and autostart for the implementations. And I rebundled the JAR without the optional dependency, but I keep having problems because now the MD5 hash is broken.</p>
  
  <p>Has anybody managed to get slf4j to work in OSGi? Or failing that, is there any way to replace that stupid dependency with some kind of Java proxy so I will not need the broken dependency anymore?</p>