简体   繁体   English

从 osgi 包中导出和导入相同的包

[英]Exporting and importing same package from an osgi bundle

I have a class org.foo.Customer in an osgi bundle Bundle1 and another class org.foo.Subscriber in another osgi bundle Bundle2 in the same osgi environment.我在 osgi bundle Bundle1有一个类org.foo.Customer ,在同一个 osgi 环境中的另一个 osgi bundle Bundle2中有另一个类org.foo.Subscriber Bundle1 exports-package org.foo . Bundle1 导出包 org.foo 。

Is it possible to import org.foo package of Bundle2 by Bundle1 .是否可以通过Bundle1 import org.foo Bundle2Bundle1包。 Will there be any conflict during runtime as the same package is specified in export and import in the manifest file of Bundle1 . Bundle1的manifest文件中export和import指定了同一个包,运行时会不会有冲突。

Split packages are strongly discouraged in OSGi.在 OSGi 中强烈不鼓励拆分包。 If you own these bundles, you should either rename one or both packages, or join the split package into one bundle.如果您拥有这些包,您应该重命名一个或两个包,或者将拆分的包合并为一个包。

Bundle2 could import the split package, but then the classloader of Bundle2 would only see the classes in Bundle1, not those internally in Bundle2. Bundle2 可以导入拆分后的包,但是Bundle2 的类加载器只能看到Bundle1 中的类,而看不到Bundle2 内部的类。

You could make one of the bundles a fragment of the other, which has the effect that they will use the same classloader.您可以使其中一个包成为另一个包的片段,这会导致它们将使用相同的类加载器。 This requires changing only the manifest of the fragment bundle, and could be an option if you for some reason cannot join the bundles or change the package names.这只需要更改片段包的清单,如果您由于某种原因无法加入包或更改包名称,这可能是一个选项。

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

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