Apache Felix Bundle Plugin Frequently Asked Questions
When I embed a dependency why do I see duplicated content?
Having two copies of classes, both unpacked and embedded as jars, is a sign that your Embed-Dependency and Export-Package instructions are overlapping. Export-Package tells BND to pull in classes found in the named packages from the build classpath and add them to the bundle, Embed-Dependency tells BND to embed (or inline if enabled) whole artifacts in the bundle.
so say I have:
Export-Package: org.objectweb.asm.*
and I have the asm artifact as a compile scope dependency, then I would see the org.objectweb.asm classes unpacked in the bundle, ie. pulled in by BND.
say I now decide to embed asm as a jar, for example with:
Embed-Dependency: *;scope=compile|runtime
I would now see the asm artifact embedded inside bundle - but I would also see the unpacked classes from before, because I'm still asking BND to pull them in (you will probably also see split package warnings during the build).
ok - so how do I embed asm as a jar, but mark its packages as exported without pulling in the unpacked classes... well, there is another export instruction added for exactly this reason:
-exportcontents: org.objectweb.asm.*
(this is <_exportcontents> in the POM because a tag can't start with '-')
this instruction is merged with Export-Package, after BND has decided on the content of the bundle - that is, it works just like Export-Package except that it won't alter the content of the bundle.
So by removing org.objectweb.asm.* from Export-Package and using the -exportcontents instruction instead along with Embed-Dependency, I can now embed the asm artifact in my bundle and export its packages:
Embed-Dependency: *;scope=compile|runtime -exportcontents: org.objectweb.asm.*