title: In an OSGi environment, how are the classpaths and classloaders set up?
body: <p>I'm confused about class visibility in OSGi. I'm running Apache Felix and loading the following bundles:</p>
  
  <ul>
  <li>the <code>antlr</code>, <code>asm</code>, <code>jpa</code> and <code>core</code> bundles from eclipselink</li>
  <li>an OSGi-fied jar for <code>javax.persistence</code> 1.99</li>
  <li>an OSGi-fied jar with the <code>com.mysql.jdbc</code> driver</li>
  <li>a bundle of my own that contains annotated entity classes and a <code>persistence.xml</code></li>
  <li>another bundle of my own that calls <code>Persistence.createEntityManagerFactory(String, Map)</code></li>
  </ul>
  
  <p>Now, what I'm confused about is which bundle must be able to see the MySQL driver. I thought this would be the bundle creating the EntityManagerFactory, but I get ClassNotFound errors when I import in that manifest. Next, I tried importing it from the eclipselink <code>jpa</code> bundle's manifest, but wrong again. Only when I import it from the manifest of the bundle containing the persistence unit (entity classes and <code>persistence.xml</code>), it works.</p>
  
  <p>So, seemingly the database driver is looked up by the clasloader for the PU's bundle, but that doesn't make sense to me. What's going on?</p>
  
  <p>I can't seem to find a straightforward documentation for this. <a href="http://www.slideshare.net/shaunmsmith/osgi-persistence-with-eclipselink" rel="nofollow noreferrer">These slides</a> give some hints, but aren't exactly comprehensive.</p>