Why do we need `Imported Packages` when we have `Required Plug-ins` in Eclipse plugin dependencies?

一曲冷凌霜 提交于 2019-12-18 11:54:00

问题


In developing Eclipse application, the dependencies tab in MANIFEST.MF has two columns.

One is Required Plug-ins and the other is Imported Packages.

Why do we need Imported Packages when we have Required Plug-ins?

The comment has it that "this plug-in depends without explicitly identifying their originating plug-in", but I'm not sure in what case one doesn't want to explicitly identify their originating plug-in, and what's the advantage of it?

ADDED

Related question - What's the difference between Eclipse Packages and Plug-ins?


回答1:


Importing a package provides an extra level of indirection over requiring a bundle.

Consider the case of some standard API... org.standard.framework. Suppose two companies implement this API, maybe you have bundles com.abc.framework and com.xyz.framework. Both of these implementation bundles would export org.standard.framework package.

Now suppose, you need an org.standard.framework implementation, but you don't particularly care which one. If you require either com.abc.framework or com.xyz.framework bundle, you are tying yourself to a particular implementation. With an import-package directive, you are letting OSGi serve as an indirection layer.

Another advantage of import-package is that your dependencies do not need to change if a package is moved to another bundle. This situation can arise during refactoring when bundles are broken up or combined.

For these reasons, OSGi spec writers now generally recommend using the relatively newer import-package directive over require-bundle. The problem is that not all of the bundles are ready for this. Many do not yet specify a version when exporting a package. This makes import-package impractical in many cases.




回答2:


Specifying the dependency on a whole plugin, rather, then only a required package may create a cyclic dependencies, if you have a lot of plugins. It's better practise to specify only packages you actually require. For the small amount of plugins of if you are sure, you are able to efficiently maintain dependencies, you are welcome to simplify your life by specifying the whole plugin. Hope this helps.



来源:https://stackoverflow.com/questions/13959891/why-do-we-need-imported-packages-when-we-have-required-plug-ins-in-eclipse-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!