Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed thirdparty JAR using BND

I have an OSGi bundle that is built using ANT and the classic BND tool. My bundle uses a library (JAR) internally, which is not available as a bundle within my OSGi container (Apache Felix). So, I am trying to embed it within my bundle, for access at runtime.

How can I embed such a library/JAR using ANT+BND? (Note : I cannot use MAVEN, using which this could have been a lot easier)

like image 695
Saket Avatar asked Sep 26 '11 11:09

Saket


1 Answers

You need two instructions in your bnd descriptor. First use Include-Resource to include the target JAR into your bundle:

Include-Resource: foo.jar

Then you need to specify that foo.jar needs to be on the bundle classpath. I assume that the bundle contents itself also needs to be part of the bundle classpath, so we need to include it as well with a dot:

Bundle-ClassPath: ., foo.jar

Note that @seh's answer about slurping the JAR's packages into your bundle with Private-Package is also correct (in that case the JAR would need to be visible on the build-time classpath). I would never use Export-Package for this though, because I think bundles should keep tight control over how much they export.

like image 56
Neil Bartlett Avatar answered Oct 01 '22 16:10

Neil Bartlett