简体   繁体   English

处理OSGI和第三方库的最佳做法

[英]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. 我正在努力找到一种合理的方法来管理足够大的代码库,更具体地说,是如何管理任何给定捆绑软件的import语句。

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). 问题是,如果您有一个捆绑包,其捆绑包对其他第三方库具有自己的依赖关系,并且如果您选择嵌入其中的一些(在我的情况下,我这样做),那么maven-bundle-plugin还将扫描那些库中的包并将它们添加为您的捆绑软件imported的内容(完全违反直觉)。

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. 我的解决方法是在import语句中消除通配符* ,但这意味着您现在必须手动维护导入列表。

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. 捆绑非OSGi第三方库有时很困难。 The maven-bundle-plugin does a good job in general by only embedding and importing what it finds as being used. 通常,maven-bundle-plugin可以很好地完成工作,只需嵌入并导入发现的使用情况即可。

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. 在这些情况下,Maven捆绑插件通常会非常小心,并且会导入比必要更多的东西。 If you are sure someting is not needed you can forbid the import by specifiying: 如果您确定不需要某物,则可以通过指定以下内容禁止导入:

Import-Packages: !somepackage, * . 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. 如果我无法避免它们,那么我将检查其中已经捆绑了许多库的servicemix捆绑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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