Insert third-party JAR using BND

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

How can I embed such a library / JAR using ANT + BND? (Note: I cannot use MAVEN, with which it could be much easier)

+6
source share
2 answers

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

 Include-Resource: foo.jar 

Then you need to specify that foo.jar should be in the bundle class path. I assume that the contents of the package itself should also be part of the bundle class path, so we must include it with a dot too:

 Bundle-ClassPath: ., foo.jar 

Please note that @seh's answer is that the JAR packets in your package using Private-Package also correct (in this case, the JAR should be visible in the assembly class path). I would never use the Export-Package for this, because I think that bundles should keep tight control over how much they export.

+11
source

There is an Ant job provided by BND called "bndwrap" . This is poorly documented. When I tried to use it, I had to read Java code to see what it was doing. (See the bnd#doWrap() method here .)

I remember that it is also possible to “embed” the dependent Jar file in another way: not directly, like Jar-in-a-Jar, but by cutting all its classes into your bundle by simply declaring the BND Directive in your Private-Package , so that packages provided by other Jar should be included in yours. Alternatively, you can specify these packages in the Export-Package directive so that they are included and exported.

0
source

Source: https://habr.com/ru/post/898062/


All Articles