`
wangchuanyin
  • 浏览: 31582 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

osgi的导入导出包

 
阅读更多
OSGI之Require-Bundle与Imported-Package
OSGI中的bundle在依赖其他的bundle的时候,有两种方式:Require-Bundle与Imported-Package。这里简单的讲讲他们之间的区别。
先看看基础的定义:
• Required-Bundle: Specify the list of plug-ins required for the operation of this plug-in.
• Imported-Package:Specify packages on which this plug-in depends without explicitly identifying their originating plug-in.
OSGI ClassLoader机制
Many bundles can share a single virtual machine (VM). Within this VM, bundles can hide packages and classes from other bundles, as well as share packages with other bundles.
Bundle共享Java虚拟机,这样的不同的bundle之间才能相互引用package。
The key mechanism to hide and share packages is the Java class loader that loads classes from a sub-set of the bundle-space using well-defined rules. Each bundle has a single class loader.
理解OSGI的Package import-export机制的关键在于明白每个bundle都有自己的Class Loader。
对于OSGI环境来说,它们是没有区别的。无论是Require-Bundle还是Imported-Package,前提都是需要把相关的packages先Export出。先看看OSGI下的ClassImport-Export关系:


区别
它们之间,仅仅只是依赖的颗粒度的区别。Required-Bundle依赖的是bundle,而Import-Package依赖的是package,而不关心是哪一个bundle export出来的。
这个区别,其实可以导致很大的用法差异。比如:
1. 在OSGI环境中有许多不同的版本的bundle的时候,required-bundle可以精确指定版本依赖,而import-package就不行了,它会根据class loader的顺序选择最先找到的class
2. 对于同一个package被许多不同的bundle同时export的时候,可以考虑使用import-package,它避免了对bundle的依赖
  • 大小: 28.2 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics