Require-Bundle 和 Import-Package 与 feature.xml 要求

发布于 2024-10-09 05:47:02 字数 549 浏览 0 评论 0原文

当构建一个由多个插件和一个功能组成的 Eclipse 插件 (lato sensu) 时,我有两种指定依赖关系的方法:

  • 在插件本身中,使用 Require-BundleMETA-INF/MANIFEST.MF 中的 Import-Package
  • 在功能的 feature.xml 文件中。

根据我的理解,在较低级别(即在插件中)声明依赖关系应该足够了。为什么我们仍然有 feature.xml requires 机制?


更新Eclipse 帮助中的 feature.xml 描述

When building an Eclipse plugin (lato sensu) which consists of multiple plugins and one feature, I have two ways of specifying dependencies:

  • in the plugins themselves, using Require-Bundle and Import-Package in META-INF/MANIFEST.MF;
  • in the feature.xml file from the feature.

In my understanding, it should be enough to declare the dependencies at the lower level, i.e. in the plugins. Why do we still have the feature.xml requires mechanism?


Update: feature.xml description in the Eclipse Help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空心↖ 2024-10-16 05:47:02

将功能间依赖机制归类为遗留机制是不正确的。虽然随着 p2 的出现,通过包清单 Require-Bundle 或 Import-Package 指定的依赖项确实会被安装,但结果可能不是您所期望的。

考虑一下您正在构建 JDT 扩展的情况。假设您只依赖 JDT 核心 api(没有 UI 扩展)。如果您仅依赖于 OSGi 依赖项,则在安装插件时,p2 将尽职尽责地安装 JDT 核心包,但不会安装 UI 包。从 OSGi 的角度来看非常好,但可能不是您想要的。

我建议坚持使用功能导入来描述您的高级依赖项,以确保它们已完整安装。仅依赖 OSGi 依赖项最适合自由浮动的捆绑包,这些捆绑包不属于应作为一个单元安装的更大的东西。

It is incorrect to categorize feature-to-feature dependency mechanism as legacy. While it is certainly true that with advent of p2, dependencies specified via bundle manifest Require-Bundle or Import-Package will be installed, the result may not be what you expect.

Consider the case where you are building an extension to JDT. Say you only depend on JDT core api (no UI extensions). If you only rely on OSGi dependencies, when your plugin is installed, p2 will dutifully install JDT core bundle, but not the UI bundle. Perfectly fine from OSGi perspective, but probably not what you intended.

I recommend sticking with feature import to describe your high level dependencies to make sure that they are installed in full. Relying only on OSGi dependencies works best for free-floating bundles that aren't part of something bigger that should be installed as a unit.

梦萦几度 2024-10-16 05:47:02

Eclipse特性是管理插件以提供更高抽象的概念。

例如,C/C++ 开发工具有二十多个插件,因此 CDT 有几个功能可以在更高级别的抽象中组织这些插件,用于核心功能、ui、构建等。

它还有助于简化安装过程,用户只需要了解CDT的顶级功能(具有友好的名称)。 P2 API 或经典安装管理可以找到插件和子功能(包括顶级功能),然后安装它们。

但是该功能无法帮助您创建高模块系统,因为它本身不提供任何功能。它不是 OSGi 规范的一部分,它继承自 Eclipse 2.x 甚至更早的版本。

Bundle是OSGi的核心。根据规范,除了使用类包声明连接之外,任何捆绑包都不能使用其他类。 Require-Bundle 和 Import-Package 是创建连线的方法。

简而言之,功能和插件是完全不同的概念。与捆绑包的导入包相比,包含插件的功能正在做不同的事情。

更新:

feature.xml 的requires 标签是遗留的。目的是定义此功能与其他插件/功能的依赖关系,以帮助更新管理器在安装或更新该功能时找到损坏的依赖关系。它确实定义了该功能与其他插件的依赖关系,但更新管理器使用它来安装或更新。 Bundle 的 Import-Package 声明了您的 Bundle 与 OSGi 系统中的另一个模块之间的实际依赖关系。

由于 eclipse 使用 p2 作为配置管理器,因此无需在 feature.xml 中声明“requires”标签。 P2 将识别您的包与“Import-Package”或“Require-Bundle”声明的其他模块之间的依赖关系。如果不满足任何依赖关系,P2 将不会安装或更新您的功能。

Eclipse feature is the notion to manage the plug-ins to provide higher abstract.

For example, there are more than twenty plug-ins for C/C++ development tools, so CDT has several features to organize those plug-ins in higher level abstract, for core functionality, ui, build and so on.

It also helps simplify the installation process, users only need know the top feature(with friendly name) of CDT. P2 API or classical install manage could find the plug-ins and sub-features including by the top feature, then install them.

However feature could NOT help you creating high module system, because itself doesn't provide any functionality. It's not a part of OSGi spec, it's inherited from Eclipse 2.x or even older version.

Bundle is the essential of OSGi. According to the spec any bundle couldn't use other classes besides declaring the wire with the package of classes. Require-Bundle and Import-Package are the ways to create the wires.

In a short word, feature and plug-in are totally different notions. Feature including plug-ins is doing different things comparing to Import-Package of bundle.

Update:

The requires tag of feature.xml is the legacy. The intend is that defining the dependencies of this feature with other plug-ins/features to help update manager to find the broken dependencies when installing or updating that feature. It does define the dependencies of that feature with other plug-ins, but it's used by update manager for installing or updating. Import-Package of bundle declares the actual and real dependency between your bundle and another module in the OSGi system.

Since eclipse uses p2 as provisioning manager, it's not necessary to declare the 'requires' tag in your feature.xml. P2 would recognize the dependencies between your bundle and other modules that are declared by 'Import-Package' or 'Require-Bundle'. P2 won't install or update your feature if any dependency is not satisfied.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文