简体   繁体   English

OSGi包与普通.JAR文件使用之间的区别

[英]Difference between OSGi bundle and normal .JAR files usage

I have recently started studying OSGi . 我最近开始研究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. 我读到可以创建bundles (which are normal java classes)并通过dynamically installing/uninstalling任何bundle在另一个bundle中使用它们。

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 . 但我似乎无法理解任何java类中的正常.JAR文件使用与bundle使用之间的区别。

Can anybody plz help me clarify it? 任何人都可以帮我澄清一下吗? Thank you. 谢谢。

There is basically no difference. 基本上没有区别。 A JAR is a bundle and a bundle is a JAR, the formats are identical. JAR是一个包,一个包是一个JAR,格式是相同的。 However, a useful bundle requires OSGi metadata in its manifest so that an OSGi framework can manage the visibility of classes between bundles. 但是, 有用的 bundle需要在其清单中包含OSGi元数据,以便OSGi框架可以管理bundle之间的类的可见性。 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. 没有这个元数据的JAR只包含不可见的类,看不到其他包中的任何类,也不能以任何方式启动它。 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. Import-Package清单标头告诉应该使哪些包对包可见,并且Export-Package定义包中应该对其他人可见的包。 Other headers provide additional features. 其他标头提供其他功能。

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的主要区别在于JAR现在都是私有的,在清单中添加元数据使其成为可以安全地与其他捆绑共享的捆绑。 OSGi makes sure violations are detected ahead of time. OSGi确保提前检测到违规行为。

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

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