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的依赖
From : http://www.xeclipse.com/?p=1195
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值