javaosgibndtools

BndTools, How to add a non-OSGi JAR? Using plain JAR breaks the whole project. Missing requirement wiring package


I'm working on this BndTools based OSGi project: https://github.com/Jafre13/ISS-Product

My project though requires a non-OSGi based library (aliasi-lingpipe - https://mvnrepository.com/artifact/de.julielab/aliasi-lingpipe/4.1.0).

And here is where the problem starts. First I tried to add the JAR directly from the Maven repository, as BndTools is supposedly compatible with Maven repositories, but it doesn't seem to work from the "Repository Browser". Even when adding the Maven Central plugin to the build.bnd file as stated in http://bnd.bndtools.org/plugins/maven.html, still yields the same result.

Giving up on having Maven working, I tried to do it the most spartan way and download the JAR myself and add it as plain JAR as specified here: http://bndtools.org/faq.html (6 How Can I Depend on a Plain JAR File at Build Time?)

This time the JAR got recognised and I could start using it in the code. But once you launch the OSGi framework everything just crumbles again as it is trying to resolve the non-OSGi class paths, resulting in a wiring error like this:

could not resolve the bundles: [slf4j.api-1.7.25 org.osgi.framework.BundleException: Unable to resolve slf4j.api [6](R 6.0): missing requirement [slf4j.api [6](R 6.0)] osgi.wiring.package; (&(osgi.wiring.package=org.slf4j.impl)(version>=1.6.0)) Unresolved requirements: [[slf4j.api [6](R 6.0)] osgi.wiring.package; (&(osgi.wiring.package=org.slf4j.impl)(version>=1.6.0))] , dk.sdu.sso.sred-0.0.0.201712041036 org.osgi.framework.BundleException: Unable to resolve dk.sdu.sso.sred [7](R 7.0): missing requirement [dk.sdu.sso.sred [7](R 7.0)] osgi.wiring.package; (osgi.wiring.package=com.aliasi.classify) Unresolved requirements: [[dk.sdu.sso.sred [7](R 7.0)] osgi.wiring.package; (osgi.wiring.package=com.aliasi.classify)] ]

So at this point I'm completely blocked and unable to proceed. I hope somebody with some OSGi experience could help here.

Greetings and thanks.


Solution

  • By adding the jar at build time you are able to compile but not to run.

    During the build bnd will see that you need the packages from the jar and create Import-Package statements for it. So in this state you would need to deploy a bundle that exports the packages. In fact this means you would have to create a bundle out of your jar.

    The other option is to embed the jar into your own bundle. This can be done by adding the packages you need as private packages. Bnd will then automatically embed these. This approach works well if the jar is really only used internally.