博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OSGi 理论: 模块元数据 (Bundle's manifest file)
阅读量:7121 次
发布时间:2019-06-28

本文共 5680 字,大约阅读时间需要 18 分钟。

OSGi 模块或者说 Bundle: 由 Java 字节码组成的相关的服务组件和依赖库,并通过 OSGi 元数据条目进行描述,按逻辑单元打包并部署的 JAR 文件

OSGi 模块元数据

由于篇幅原因,未详尽之处请参考 的 3.2 小节

存放于标准 JAR 文件的 manifest file

META-INF/MANIFEST.MF
一个 bundle 元数据实例
$ java -jar bnd-2.4.0.jar print alipay2-1.4.0.jar[MANIFEST alipay2-1.4.0]Bnd-LastModified                         1457335746729                           Build-Jdk                                1.8.0_66                                Built-By                                 steven                                  Bundle-Blueprint                         OSGI-INF/blueprint/context.xml          Bundle-Category                          Aves :: Pitta                           Bundle-Description                       The Alipay barcode pay 2 implementationsBundle-DocURL                            http://git.abacus.com.cn                Bundle-ManifestVersion                   2                                       Bundle-Name                              Pitta :: Barcode Pay :: Alipay 2        Bundle-SymbolicName                      org.aves.pitta.alipay2                  Bundle-Vendor                            SiChuan Abacus Aves Team                Bundle-Version                           1.4.0                                   Created-By                               Apache Maven Bundle Plugin              Export-Service                           org.aves.pitta.api.RemotePaymentServiceDelegate;paysrvCode=102,org.aves.pitta.api.RemotePaymentPendingHolder;paysrvCode=102Import-Package                           javax.json;version="[1.0,2)",org.apache.http,org.apache.http.client;version="[4.5,5)",org.apache.http.client.entity;version="[4.5,5)",org.apache.http.client.methods;version="[4.5,5)",org.apache.http.impl.client;version="[4.5,5)",org.apache.http.message,org.apache.http.util,org.apache.log4j;version="[1.2,2)",org.aves.iora.base;version="[1.3,2)",org.aves.iora.security;version="[1.3,2)",org.aves.iora.util;version="[1.3,2)",org.aves.pitta.api;version="[1.4,2)",org.osgi.service.blueprint;version="[1.0.0,2.0.0)",org.slf4j;version="[1.7,2)"Import-Service                           org.aves.pitta.api.NativeRepository;multiple:=falseManifest-Version                         1.0                                     Require-Capability                       osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"Tool                                     Bnd-3.0.0.201509101326                  [IMPEXP]Import-Package  javax.json                             {version=[1.0,2)}  org.apache.http                          org.apache.http.client                 {version=[4.5,5)}  org.apache.http.client.entity          {version=[4.5,5)}  org.apache.http.client.methods         {version=[4.5,5)}  org.apache.http.impl.client            {version=[4.5,5)}  org.apache.http.message                  org.apache.http.util                     org.apache.log4j                       {version=[1.2,2)}  org.aves.iora.base                     {version=[1.3,2)}  org.aves.iora.security                 {version=[1.3,2)}  org.aves.iora.util                     {version=[1.3,2)}  org.aves.pitta.api                     {version=[1.4,2)}  org.osgi.service.blueprint             {version=[1.0.0,2.0.0)}  org.slf4j                              {version=[1.7,2)}

以上为使用 (Bundle - removing the vowels) 输出以前项目其中的一个模块的元数据

初看有点象药品的说明书。不过这是交给 OSGi 运行时去识别的。我们在这儿只是将此作为案例,取其中主要的条目进行说明。

Bundle-Blueprint 一个类似于 Springframework 的组件管理容器,提供 实现,详细请参考 项目。

类似的还有 、、等

Bundle-Category, Bundle-Description, Bundle-DocURL, Bundle-Name, Bundle-Vendor 是关于这个模块的说明信息,有助于部署人员了解模块。
Bundle-ManifestVersion, Bundle-SymbolicNameBundle-Version 组合成 bundle 的唯一性标识符(Identification),用于 OSGi 运行时识别模块和其他一致性检查等。
Import-Package 当前这个模块所依赖的由其它或系统 bundles 提供的包,也就是说只有当引入了这些包,我才拥有这些包内类(class)的访问权 (注:Java 标准API由 OSGi 运行时代为引入,不需要在此申明)
Export-Package 当前这个模块没有这个条目,也就是说当前这个 bundle 的所有代码为私有,是一个服务接口的实现模块。并且通过 blueprint 完成服务注册。
Export-Service 这个已经没有使用了,留下只是为了兼容以前的版本。当前是通过 blueprint 完成服务注册。

我们再看看部署后,由 OSGi 的运行时输出的报告

Karaf console

karaf@root()> bundle:headers 243Pitta :: Barcode Pay :: Alipay 2 (243)--------------------------------------Bnd-LastModified = 1456980670717Build-Jdk = 1.8.0_66Built-By = stevenCreated-By = Apache Maven Bundle PluginManifest-Version = 1.0Tool = Bnd-3.0.0.201509101326Bundle-Blueprint = OSGI-INF/blueprint/context.xmlBundle-Category = Aves :: PittaBundle-Description = The Alipay barcode pay 2 implementationsBundle-DocURL = http://git.abacus.com.cnBundle-ManifestVersion = 2Bundle-Name = Pitta :: Barcode Pay :: Alipay 2Bundle-SymbolicName = org.aves.pitta.alipay2Bundle-Vendor = SiChuan Abacus Aves TeamBundle-Version = 1.4.0.SNAPSHOTExport-Service =     org.aves.pitta.api.RemotePaymentPendingHolder;paysrvCode=102,    org.aves.pitta.api.RemotePaymentServiceDelegate;paysrvCode=102Import-Service =     org.aves.pitta.api.NativeRepository;multiple:=falseRequire-Capability =     osgi.ee;filter:=(&(osgi.ee=JavaSE)(version=1.8))Import-Package =     javax.json;version="[1.0,2)",    org.apache.http,    org.apache.http.client;version="[4.5,5)",    org.apache.http.client.entity;version="[4.5,5)",    org.apache.http.client.methods;version="[4.5,5)",    org.apache.http.impl.client;version="[4.5,5)",    org.apache.http.message,    org.apache.http.util,    org.apache.log4j;version="[1.2,2)",    org.aves.iora.base;version="[1.3,2)",    org.aves.iora.security;version="[1.3,2)",    org.aves.iora.util;version="[1.3,2)",    org.aves.pitta.api;version="[1.4,2)",    org.osgi.service.blueprint;version="[1.0.0,2.0.0)",    org.slf4j;version="[1.7,2)"

这些有什么用?

  1. 我们的模块有身份了,不在是个三无产品。药品的说明书算是条目最多,内容最详细的说明书了,原因你我都知道。这个元数据不是有点一样吗?
  2. 我们不用在担心运行期的类连接错误,因为我们有[1.4,2)这样的版本控制。
  3. 模块与模块之间优雅的遵守着外交礼仪打交道。
  4. 为部署于 OSGi 运行环境下的生命周期管理和服务管理做好了准备

转载地址:http://dzdel.baihongyu.com/

你可能感兴趣的文章
day24 Pythonpython 面向对象设计 类
查看>>
FJUT Home_W的gcd(乱搞)题解
查看>>
[爬虫] requests库
查看>>
Cap09_项目人力资源管理
查看>>
if-else选择结构
查看>>
【100题】第五十七题 用两个栈实现队列
查看>>
hdoj 2073--无限的路
查看>>
JAVAWEB项目如何实现验证码
查看>>
JAVA 从头开始<二>
查看>>
RabbitMQ安装
查看>>
翻译:Bing地图瓦片体系
查看>>
hdu3315 /最大权最佳匹配(最大权下尽量不改变次序)(有权田忌赛马类问题)/费用流...
查看>>
ABP前端使用阿里云angular2 UI框架NG-ZORRO分享
查看>>
神秘的subsys_initcall【转】
查看>>
linux RTC 驱动模型分析【转】
查看>>
EPLAN Electric P8 2.0即将到来,着实令人期待-转caodaping
查看>>
面向对象与面向过程的对比——以自动售票机程序为例
查看>>
【Alpha】Scrum Meeting 3
查看>>
枚举和实用类
查看>>
python 里面的%s和%r的区别
查看>>