问题描述
在开发 Eclipse 应用程序时,MANIFEST.MF 中的依赖项选项卡有两列.
In developing Eclipse application, the dependencies tab in MANIFEST.MF has two columns.
一个是Required Plug-ins
,另一个是Imported Packages
.
当我们有必需的插件
时,为什么还需要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?
相关问题 - Eclipse 包和插件有什么区别?
推荐答案
导入包提供了额外的间接级别,而不是需要包.
Importing a package provides an extra level of indirection over requiring a bundle.
考虑一些标准 API 的情况... org.standard.framework
.假设有两家公司实现了这个 API,也许你有包 com.abc.framework
和 com.xyz.framework
.这两个实现包都会导出 org.standard.framework
包.
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.
现在假设,您需要一个 org.standard.framework
实现,但您并不特别关心是哪一个.如果您需要 com.abc.framework
或 com.xyz.framework
捆绑包,那么您将自己绑定到特定的实现.使用 import-package 指令,您可以让 OSGi 充当间接层.
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.
import-package 的另一个优点是,如果将一个包移动到另一个包,您的依赖项不需要更改.当捆绑包被分解或组合时,在重构期间可能会出现这种情况.
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.
由于这些原因,OSGi 规范编写者现在通常建议使用相对较新的 import-package 指令而不是 require-bundle.问题是并非所有的捆绑包都为此做好了准备.许多人在导出包时还没有指定版本.这使得 import-package 在许多情况下变得不切实际.
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.
这篇关于当我们在 Eclipse 插件依赖项中有 `Required Plug-ins` 时,为什么我们需要 `Imported Packages`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!