本文共 5680 字,大约阅读时间需要 18 分钟。
OSGi 模块或者说 Bundle: 由 Java 字节码组成的相关的服务组件和依赖库,并通过 OSGi 元数据条目
进行描述,按逻辑单元打包并部署的 JAR
文件
由于篇幅原因,未详尽之处请参考 的 3.2 小节
存放于标准 JAR 文件的 manifest file
META-INF/MANIFEST.MF
$ 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-SymbolicName
和 Bundle-Version
组合成 bundle 的唯一性标识符(Identification),用于 OSGi 运行时识别模块和其他一致性检查等。Import-Package
当前这个模块所依赖的由其它或系统 bundles 提供的包,也就是说只有当引入了这些包,我才拥有这些包内类(class)的访问权 (注:Java 标准API由 OSGi 运行时代为引入,不需要在此申明) Export-Package
当前这个模块没有这个条目,也就是说当前这个 bundle 的所有代码为私有,是一个服务接口的实现模块。并且通过 blueprint
完成服务注册。Export-Service
这个已经没有使用了,留下只是为了兼容以前的版本。当前是通过 blueprint
完成服务注册。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.4,2)
这样的版本控制。转载地址:http://dzdel.baihongyu.com/