OSGI学习之路之Require-Bundle与Imported-Package
2017-07-15 23:07
381 查看
1 OSGI之Require-Bundle与Imported-Package
OSGI中的bundle在依赖其他的bundle的时候,有两种方式:Require-Bundle与Imported-Package。这里简单的讲讲他们之间的区别。
先看看基础的定义:
• Required-Bundle: Specify thelist of plug-ins required for the operation of this plug-in.
• 指定操作此插件所需的插件列表。
• Imported-Package:Specifypackages on which this plug-in depends without explicitly identifying their originatingplug-in.
• 指定此插件所依赖的软件包,而不明确标识其来源插件。
1.1 OSGIClassLoader机制
Many bundles can share a single virtualmachine (VM). Within this VM, bundles can hide packages and classes from otherbundles, as well as share packages with other bundles.
Bundle共享Java虚拟机,这样的不同的bundle之间才能相互引用package。
The key mechanism to hide and sharepackages is the Java class loader that loads classes from a sub-set of thebundle-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关系:
1.2 区别
它们之间,仅仅只是依赖的颗粒度的区别。Required-Bundle依赖的是bundle,而Import-Package依赖的是package,而不关心是哪一个bundle export出来的。
这个区别,其实可以导致很大的用法差异。比如:
1. 在OSGI环境中有许多不同的版本的bundle的时候,required-bundle可以精确指定版本依赖,而import-package就不行了,它会根据classloader的顺序选择最先找到的class
2. 对于同一个package被许多不同的bundle同时export的时候,可以考虑使用import-package,它避免了对bundle的依赖
OSGI中的bundle在依赖其他的bundle的时候,有两种方式:Require-Bundle与Imported-Package。这里简单的讲讲他们之间的区别。
先看看基础的定义:
• Required-Bundle: Specify thelist of plug-ins required for the operation of this plug-in.
• 指定操作此插件所需的插件列表。
• Imported-Package:Specifypackages on which this plug-in depends without explicitly identifying their originatingplug-in.
• 指定此插件所依赖的软件包,而不明确标识其来源插件。
1.1 OSGIClassLoader机制
Many bundles can share a single virtualmachine (VM). Within this VM, bundles can hide packages and classes from otherbundles, as well as share packages with other bundles.
Bundle共享Java虚拟机,这样的不同的bundle之间才能相互引用package。
The key mechanism to hide and sharepackages is the Java class loader that loads classes from a sub-set of thebundle-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关系:
1.2 区别
它们之间,仅仅只是依赖的颗粒度的区别。Required-Bundle依赖的是bundle,而Import-Package依赖的是package,而不关心是哪一个bundle export出来的。
这个区别,其实可以导致很大的用法差异。比如:
1. 在OSGI环境中有许多不同的版本的bundle的时候,required-bundle可以精确指定版本依赖,而import-package就不行了,它会根据classloader的顺序选择最先找到的class
2. 对于同一个package被许多不同的bundle同时export的时候,可以考虑使用import-package,它避免了对bundle的依赖
相关文章推荐
- OSGI之Require-Bundle与Imported-Package
- OSGI之Require-Bundle与Imported-Package
- OSGI之Require-Bundle与Imported-Package
- osgi实战学习之路:2. maven+maven-bundle-plugin+karaf搭建osgi之HelloWorld
- osgi实战学习之路:4.Bundle
- osgi实战学习之路:2. maven+maven-bundle-plugin+karaf搭建osgi之HelloWorld
- 【OSGi】Require-Bundle与Import-Package
- osgi实战学习之路:5.生命周期及利用命令、装饰者模式实现基于socket交互Bundle命令demo
- osgi实战学习之路:8. Service-3之ServiceTracker
- OSGi 学习之路 - 概述什么是OSGi框架
- OSGi 学习之路(3) - osgi的helloworld
- osgi 中require-bundle import-package 的差别
- java学习之路 之 面向对象编程-面向对象-关键字(this、package、import)及java中主要包的介绍
- osgi实战学习之路:3. osgi分层概念及相互合作demo
- [原创]java WEB学习笔记54:Struts2学习之路--- 编写Struts2 的第一个程序,HelloWord,简述 package ,action,result
- OSGi 学习之路(4) - osgi的模块化 java在模块化的局限性
- 菜鸟的学习之路(7) — 包(package)、Object类和String类
- Require-Bundle与Import-Package
- OSGi学习之install bundle
- OSGi 学习之路(4) - osgi的模块化 java在模块化的局限性