OSGI:是否可以导入包并添加可见性:=重新导出?

发布于 2024-09-14 03:50:26 字数 92 浏览 7 评论 0原文

我想导入一个包而不是清单中的 require 包,并且让所有需要前一个包的包继承导入的包。我假设可以设置可见性:重新导出,但如果我有此选项,Eclipse 不会抱怨...

i would like to import a package rather than require bundle in a manifest and have all bundles that require the former package inherit the imported package. I am assuming that it is possible to set visibility: reexport, but Eclipse does not complain if i had this option...

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

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

发布评论

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

评论(5

梦过后 2024-09-21 03:50:27

我显然错过了“回复评论”链接,所以请原谅我在这里回复评论中的问题......

无论您是否处于“层次结构”中并没有真正的区别。第一个包在不同的上下文中使用,因此它们并不总是在知道它们想要的容器中使用。其次,捆绑包仍然不会使用“层次结构”中可用的所有内容,因此执行它只会导致依赖项扇出,因为真正的依赖项是隐藏的。

I'm apparently missing the "reply to comment" link, so forgive me that I'm replying to the question in the comments here...

Whether you are in a "hierarchy" or not doesn't really make a difference. First bundles are used in different contexts, so they won't always be used in a container that knows that they want. Second, a bundle still doesn't use everything available to it in a "hierarchy", so acting it does just leads to dependency fan out, since the real dependencies are hidden.

戏剧牡丹亭 2024-09-21 03:50:27

我不确定你的问题是什么。如果您不想需要捆绑包,则必须导入所需的所有包。要生成此列表,您可以使用 maven-bundle-插件(用于 Maven 项目)。如果您不想生成所需导入的具体列表,那么您可以尝试

DynamicImport-Package: *

按需导入所需的包。

I am not sure what your problem is. If you do not want to require a bundle, you have to import all packages you need. To generate this list you can use the maven-bundle-plugin (for maven projects). If you do not want to generate the concrete list of needed imports, than you can try

DynamicImport-Package: *

which should import the needed packages on demand.

怎樣才叫好 2024-09-21 03:50:26

这是不可能的,也没有必要。使用 Import-Package 的包可以简单地从导出它的原始包中获取包;无需通过中间包“路由”依赖关系。

这是 Import-Package 的最大优点之一:导入包既不知道也不关心它从哪个其他包中获取包。

It's not possible and it's not necessary either. A bundle using Import-Package can simply obtain the package from the original bundle that exports it; there is no need to "route" the dependency through an intermediate bundle.

This is one of the biggest advantages of Import-Package: an importing bundle neither knows nor cares which other bundle(s) it's getting the packages from.

野侃 2024-09-21 03:50:26

您只能在需要捆绑包时重新导出。

Import-Package 应优先于 Require-Bundle 或 DynamicImport-Package。仅当您必须处理拆分包时,前者才是真正必要的,而后者仅用于解决您事先不知道类名的情况(例如,类似 SPI 的情况),尽管它也可以安全地用作可选的类似导入的设施。一般来说,您应该避免隐藏依赖项(例如,广泛的动态导入)或掩盖它们(例如,需要捆绑包)的事情。 Require-Bundle 支持重新导出的事实是一个不应该做出的决定,并且此功能没有合理的用例,它所做的一切都进一步模糊了依赖关系并造成了混乱。

You can only reexport when requiring bundles.

Import-Package should be preferred over Require-Bundle or DynamicImport-Package. The former is only really necessary if you must deal with split packages whereas the latter was only intended to address situations where you didn't know the class name in advance (e.g., SPI-like situations), although it can also be used safely as an optional import-like facility. In general, you should be avoiding things that hide dependencies (e.g., broad dynamic imports) or obscure them (e.g., requiring bundles). The fact that Require-Bundle supports reexporting is a decision that should have never been made and there is no reasonable use case for this feature, all it does it further obscure dependencies and create a tangled mess.

悲欢浪云 2024-09-21 03:50:26

不可以,无法重新导出包。为此,您需要使用捆绑包或不同的类加载策略。

No, it's not possible to reexport a package. For that you will need to use a bundle, or a different class loading strategy.

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