简体   繁体   中英

Best practices when dealing with OSGI & 3rd party libraries

I'm struggling to find a reasonable approach to manage a big enough code base, more specifically, how to manage import statements for any given bundle.

The problem is, if you have a bundle with has his own dependencies to other 3rd party libraries, and if you choose to embed some of them (in my case I do), the maven-bundle-plugin will also scan packages from those libraries and add them as imported by your bundle (which is completely counter-intuitive).

A work around my be to get rid of the wildcard * in your import statements, but this means that now you have to maintain the list of imports by hand.

So how do you guys manage this problem ? Am I missing something here ?

Any advice will be greatly appreciated

Bundling a non OSGi third party library is sometimes difficult. The maven-bundle-plugin does a good job in general by only embedding and importing what it finds as being used.

The problem is that many libaries have a lot of dependencies and especially a lot of optional dependencies. In these cases the maven bundle plugin often is careful and imports more than necessary. If you are sure someting is not needed you can forbid the import by specifiying:

Import-Packages: !somepackage, * .

My personal approach of this is to try to avoid libraries with a lot of external dependencies. If I can not avoid them then I check at servicemix bundles where many libaries are already bundled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM