When I am building a bundle, I need to embed a few jars (http-core and http-client) in my case. Using maven with flex plugin I get huge Import list - some of the stuff that I do not need. As of right now I am just negating the packages that I do not need in <Import-Package>
, but I could also use Import-Package: resolution:=optional
. I was wondering what is the preferred way and what are the advantages/disadvantages of either approaches?
Unfortunately people include a lot of "nice to have parts" (usually called utils) that cause these imports. Very often the culprits are separate of the core code that you want to use. If you use bndtools then you can easily inspect how the dependencies run.
In bndtools and maven you use bnd, and bnd makes it very easy to only copy part of the JAR into your bundle. That way you can minimize the dependencies. Just use Private-Package to copy the packages you really need and then look at the imports. If you import something that you think you need, add it to Private-Package (in bndtools you can do this with drag and drop).
At the end you can probably get rid of many unnecessary imports. However, there are usually some left. In that case decorate them with resolution:=optional in the Import-Package statement:
Import-Package: com.oracle.whatever; resolution:=optional, *
Don't forget the * at the end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With