title: Embedding JARs in an OSGi Bundle in Eclipse
body: <p>I need to embed a third-party JAR file in the OSGi bundle that I'm developing in Eclipse. I've done a lot of searching and reading, and I keep seeing the same things over and over again:</p>
  
  <ol>
  <li>I really shouldn't be doing this. It isn't the OSGi "way" of doing things.</li>
  <li>It's actually pretty easy to do. Just embed the JAR at the root of your bundle and specify <code>Bundle-ClassPath: ., jar_filename.jar</code> in your manifest.</li>
  </ol>
  
  <p>Okay. Except the JAR I'm embedding is tiny and unlikely to be used by anything else I will ever implement on this closed system, so it's a lot easier to embed it so that users only have to download one bundle (ease of use for the end-user is vital). So I'm going to go against convention and embed it.</p>
  
  <p>Now, in the IDE, everything is kosher. I dropped the JAR in the <code>src</code> folder of my Eclipse project and configured the project's build path to include it using the "add jar" button (not the "add external jar", since I'm lead to believe that will use absolute path) of the "configure build path" dialogue. I also added the <code>Bundle-ClassPath</code> line to my manifest file. In the IDE, all my imports resolve fine (because it's in the build path), but when I export it as a bundle (default options), the error log shows that the imports could not be resolved.</p>
  
  <p>I checked the final bundle JAR file that was generated, and the third-party JAR is nested inside (at the root) as expected, but as soon as it tries to import objects from that library, it fails.</p>
  
  <p>Included below is my (very basic) <code>MANIFEST.MF</code>. Am I missing something? Do I need to list it as an import-package in addition to listing it on the bundle-classpath? Do I need to export it (why?)? Am I mis-using bundle-classpath? Do I need to do something differently because I'm using Eclipse?</p>
  
  <pre><code>Manifest-Version: 1.0
  Bundle-ManifestVersion: 2
  Bundle-Name: ZWave Demo
  Bundle-SymbolicName: com.wbarlow.zwavedemo
  Bundle-Version: 1.0.0.qualifier
  Bundle-Activator: com.wbarlow.zwavedemo.internal.Activator
  Bundle-Vendor: WBARLOW
  Bundle-RequiredExecutionEnvironment: J2SE-1.5
  Import-Package: org.osgi.framework;version="1.3.0"
  Bundle-ClassPath: .,
   rxtx-2.1.7.jar
  </code></pre>
  
  <p>EDIT: I solved this by re-doing it all using the GUI rather than editing the .MF file directly. I guess Eclipse sets some background configuration when you do that.</p>