Java OSGi 包和普通 .JAR 文件使用之间的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20258698/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between OSGi bundle and normal .JAR files usage
提问by Amrit
I have recently started studying OSGi
. I read that one can create bundles
(which are normal java classes)
and use them in another bundle by dynamically installing/uninstalling
any bundle.
我最近开始学习OSGi
。我读到可以bundles
(which are normal java classes)
通过dynamically installing/uninstalling
任何捆绑包在另一个捆绑包中创建和使用它们。
But I can't seem to understand the difference between a normal .JAR
file usage in any java class and between usage of a bundle
.
但我似乎无法理解.JAR
任何 java 类中的正常文件使用与bundle
.
Can anybody plz help me clarify it? Thank you.
有人可以帮我澄清一下吗?谢谢你。
采纳答案by Peter Kriens
There is basically no difference. A JAR is a bundle and a bundle is a JAR, the formats are identical. However, a usefulbundle requires OSGi metadata in its manifest so that an OSGi framework can manage the visibility of classes between bundles. A JAR without this metadata would only contain invisible classes, could not see any classes from other bundles, nor could it get started in any way. The Import-Package manifest header tells what packages should be made visible to the bundle, and the Export-Package defines the packages in the bundle that should be made visible to others. Other headers provide additional features.
基本上没有区别。JAR 是一个包,一个包是一个 JAR,格式是相同的。然而,一个有用的包需要在其清单中的 OSGi 元数据,以便 OSGi 框架可以管理包之间类的可见性。没有这个元数据的 JAR 将只包含不可见的类,不能看到来自其他包的任何类,也不能以任何方式启动。Import-Package 清单标头说明哪些包应该对 bundle 可见,Export-Package 定义了 bundle 中应该对其他人可见的包。其他标头提供附加功能。
With the traditional class path everything is shared and global, having the same class on the class path twice is not flagged anywhere, one is just ignored. The key difference with OSGi is that a JAR is now all private, adding metadata in the manifest makes it a bundle that can safely share with other bundles. OSGi makes sure violations are detected ahead of time.
使用传统的类路径,一切都是共享的和全局的,在类路径上两次使用相同的类不会在任何地方标记,只是忽略一个。与 OSGi 的主要区别在于 JAR 现在都是私有的,在清单中添加元数据使其成为可以安全地与其他包共享的包。OSGi 确保提前检测到违规。