使用OSGI模块化标准构建Java EE项目,其中比较繁琐的一个方面就是Bundle资源的获取,因为很多开源框架官方都没有发布Bundle版本的Jar文件,这也是使用OSGI开发企业应用首先要解决的问题。

本篇文章中,我们来总结一下Bundle资源的获取途径,包括如下几种方式:

一、从SpringSource Enterprise Bundle Repository下载

这种方式前面文章中已经提到过,SpringSource Enterprise Bundle Repository是目前最全面的Bundle资源网站,地址如下:

http://ebr.springsource.com/repository/app/bundle

首页面如下图:

我们可以根据首字母进行Bundle资源的分类查找,也可以在网站右侧搜索框进行模糊搜索,SpringSource Enterprise Bundle Repository网站提供了大量的工具包及开源框架的Bundle资源,日常开发中需要的绝大多数的Bundle都可以从该网站获取。

二、从Eclipse Orbit获取

Eclipse Orbit是Eclipse组织维护的Bundle资源库,它的Bundle资源并不没有SpringSource Enterprise Bundle Repository那么全面,根据Eclipse Orbit官网介绍,它是用于提供Eclipse项目中依赖的第三方库或者框架的Bundle资源,并且所有第三方库或框架使用的开源协议必须与Eclipse Public Licence(EPL协议)兼容。

Eclipse Orbit官网地址:http://www.eclipse.org/orbit/

三、使用BND工具將Jar包转换为Bundle

这种方式非常实用,因为一些比较冷门的框架或者工具包,可能没有办法直接从网上下载到,这时候我们可以使用BND工具將普通的Jar包转换为Bundle。

下面就来介绍BND工具的获取与使用步骤:

1、下载BND工具

BND工具实际上就是一个Jar包,读者可以通过搜索引擎搜索bnd-2.1.0.jar,下载该文件。

笔者在CSDN网站上传了一份,下载地址如下:

http://download.csdn.net/detail/rongbo_j/9738274

获取到该文件后,可以通过如下命令运行工具查看帮助信息:

java -jar bnd-2.1.0.jar

帮助信息如下:

Available commands:

  baseline          - Compare a newer bundle to a baselined bundle and provide
versioning advice
bnd - The swiss army tool for OSGi
build - Build a project. This will create the jars defined in the
bnd.bnd and sub-builders.
buildx - Build project, is deprecated but here for backward
compatibility
bump - Bumps the version of a project
clean - Clean a project
convert - Converter to different formats
create - Create jar, used to support backward compatible java jar
commands
debug - Show a lot of info about the project you're in
deliverables - Show all deliverables from this workspace. with their
current version and path.
diff - Diff jars
digest - Digests a number of files
do - Execute a file based on its extension. Supported
extensions are: bnd (build), bndrun (run), and jar (print)
eclipse - Show info about the current directory's eclipse project
extract - Extract files from a JAR file, equivalent jar command
x[vf] (syntax supported)
grep - Grep the manifest of bundles/jar files.
info - Show key project variables
macro - Show macro value
maven - Maven bundle command
package - Package a bnd or bndrun file into a single jar that
executes with java -jar <>.jar
print - Printout the JAR
project - Execute a Project action, or if no parms given, show
information about the project
release - Release this project
repo - Manage the repositories
run - Run a project in the OSGi launcher
runtests - Run OSGi tests and create report
schema - Highly specialized function to create an overview of
package deltas in ees
select - Helps finding information in a set of JARs by filtering on
manifest data and printing out selected information.
settings - Set bnd/jpm global variables
source - Merge a binary jar with its sources. It is possible to
specify source path
syntax - Access the internal bnd database of keywords and options
test - Test a project according to an OSGi test
type - List files int a JAR file, equivalent jar command t[vf]
(syntax supported)
verify - Verify jars
version - Show version information about bnd
view - View a resource from a JAR file.
wrap - Wrap a jar
xref - Show a cross references for all classes in a set of jars.

可以看到,该工具可选的参数很多,但是我们实际用到的参数并不多,接下来介绍工具的使用。

2、將Jar包转换为Bundle

接着我们就使用BND工具將普通Jar包转换为Bundle,以dom4j-1.6.1.jar为例,將dom4j-1.6.1.jar和bnd-2.1.0.jar放在同一个目录中。

然后在该目录下新建一个org.csdn.dom4j-1.6.1.bnd文件,内容如下:

#org.csdn.dom4j-1.6.1.bnd
-classpath:dom4j-1.6.1.jar version:1.6.1
Bundle-SymbolicName:org.csdn.dom4j
Bundle-Version:${version}
Export-Package:*;version=${version}

然后执行如下命令:

java -jar bnd-2.1.0.jar org.csdn.dom4j-1.6.1.bnd

命令执行完毕后,就会在相同目录下生成一个org.csdn.dom4j-1.6.1.jar文件,如下图:



该文件已经是一个完整的Bundle了,我们解压org.csdn.dom4j-1.6.1.jar文件,然后查看META-INF/MANIFEST.MF文件,内容如下:

Manifest-Version: 1.0
Bnd-LastModified: 1484488037644
Bundle-ManifestVersion: 2
Bundle-Name: org.csdn.dom4j
Bundle-SymbolicName: org.csdn.dom4j
Bundle-Version: 1.6.1
Created-By: 1.8.0_11 (Oracle Corporation)
Export-Package: org.dom4j;version="1.6.1";uses:="org.dom4j.rule,org.dom4
j.tree,org.jaxen,org.xml.sax",org.dom4j.bean;version="1.6.1";uses:="org
.dom4j,org.dom4j.tree,org.xml.sax",org.dom4j.datatype;version="1.6.1";u
ses:="com.sun.msv.datatype,com.sun.msv.datatype.xsd,org.dom4j,org.dom4j
.tree,org.relaxng.datatype",org.dom4j.dom;version="1.6.1";uses:="org.do
m4j,org.dom4j.tree,org.w3c.dom",org.dom4j.dtd;version="1.6.1",org.dom4j
.io;version="1.6.1";uses:="javax.xml.namespace,javax.xml.stream,javax.x
ml.stream.events,javax.xml.stream.util,javax.xml.transform.sax,org.dom4
j,org.dom4j.tree,org.gjt.xpp,org.w3c.dom,org.xml.sax,org.xml.sax.ext,or
g.xml.sax.helpers,org.xmlpull.v1",org.dom4j.jaxb;version="1.6.1";uses:=
"javax.xml.bind,org.dom4j,org.dom4j.io,org.xml.sax",org.dom4j.rule;vers
ion="1.6.1";uses:="org.dom4j,org.jaxen",org.dom4j.rule.pattern;version=
"1.6.1";uses:="org.dom4j,org.dom4j.rule",org.dom4j.swing;version="1.6.1
";uses:="javax.swing.table,javax.swing.tree,org.dom4j,org.jaxen",org.do
m4j.tree;version="1.6.1";uses:="org.dom4j,org.dom4j.rule,org.xml.sax",o
rg.dom4j.util;version="1.6.1";uses:="org.dom4j,org.dom4j.rule,org.dom4j
.tree,org.jaxen,org.xml.sax",org.dom4j.xpath;version="1.6.1";uses:="org
.dom4j,org.dom4j.rule,org.jaxen,org.jaxen.pattern",org.dom4j.xpp;versio
n="1.6.1";uses:="org.dom4j,org.gjt.xpp"
Import-Package: com.sun.msv.datatype,com.sun.msv.datatype.xsd,javax.swin
g.table,javax.swing.tree,javax.xml.bind,javax.xml.namespace,javax.xml.p
arsers,javax.xml.stream,javax.xml.stream.events,javax.xml.stream.util,j
avax.xml.transform,javax.xml.transform.sax,javax.xml.transform.stream,o
rg.gjt.xpp,org.jaxen,org.jaxen.dom4j,org.jaxen.pattern,org.jaxen.saxpat
h,org.relaxng.datatype,org.w3c.dom,org.xml.sax,org.xml.sax.ext,org.xml.
sax.helpers,org.xmlpull.v1
Tool: Bnd-2.1.0.20130426-122245

实际上,普通Jar包和Bundle本质的区别也就在于MANIFEST.MF文件内容,BND工具的工作原理也只是生成MANIFEST.MF文件,指定导入导出的包而已。

除此之外,我们还可以在Bundle中直接使用Jar包,如果一个工具库只需要在其中一个Bundle中使用,只需要使用Bundle-ClassPath元数据头指定Jar包的路径即可,并不一定非要把Jar包转成Bundle去使用,本文内容就介绍这么多,后面文章会介绍如何使用OSGI开发WEB应用,以及如何整合MVC框架。

转载请注明本文地址:http://blog.csdn.net/Rongbo_J/article/details/54179073

OSGI企业应用开发(十一)Bundle资源获取途径的更多相关文章

  1. OSGI企业应用开发(十三)OSGI Web应用开发(二)

    上篇文章介绍了OSGI Web应用的两种开发模式,并把Jetty应用服务器以Bundle的形式整合到Equinox容器中,已这种模式开发Web应用,所有的应用程序资源,例如Servlet.JSP.HT ...

  2. OSGI企业应用开发(十二)OSGI Web应用开发(一)

    前面文章中介绍了如何在OSGI应用中整合Spring和Mybatis框架,本篇文章开始介绍如何使用OSGI技术开发Web应用.对于传统的Java EE应用,应用中涉及到的Web元素无非就是Servle ...

  3. OSGI企业应用开发(四)使用Blueprint整合Spring框架(一)

    上篇文章中介绍了如何使用独立的Equinox发行包搭建OSGI运行环境,而不是依赖与具体的Eclipse基础开发工具,本文开始介绍如何使用Blueprint將Spring框架整合到OSGI中. 一.开 ...

  4. OSGI企业应用开发(三)Eclipse中搭建Equinox运行环境

    上篇文章介绍了如何在Eclipse中搭建Felix的运行环境,我们需要將Bundle发布到Felix框架的bundle目录下,Felix框架启动时才会自动加载这些Bundle,否则需要在Felix框架 ...

  5. OSGI企业应用开发(二)Eclipse中搭建Felix运行环境

    上篇文章介绍了什么是OSGI以及使用OSGI构建应用的优点,接着介绍了两款常用的OSGI实现,分别为Apache Felix和Equinox,接下来开始介绍如何在Eclipse中使用Apache Fe ...

  6. OSGI企业应用开发(一)OSGI简介

    一.OSGI简介 OSGI全称为Open Service Gateway Initiative(开放服务网关规范),有两个层面的含义,一方面它指OSGi Alliance组织:另一方面指该组织制定的一 ...

  7. OSGI企业应用开发(十四)整合Spring、Mybatis、Spring MVC

    作为一个企业级的Web应用,MVC框架是必不可少的.Spring MVC目前使用也比较广泛,本文就来介绍一下如何在OSGI应用中实现Spring.Mybatis.Spring MVC框架的整合,其中S ...

  8. OSGI企业应用开发(八)整合Spring和Mybatis框架(一)

    到目前为止,我们已经学习了如何使用Blueprint將Spring框架整合到OSGI应用中,并学习了Blueprint&Gemini Blueprint的一些使用细节.本篇文章开始,我们將My ...

  9. OSGI企业应用开发(七)细说Blueprint & Gemini Blueprint(二)

    上篇文章介绍了标准的Blueprint 规范与 Gemini Blueprint如何自定义Bean配置文件路径,本文接着上篇文章继续介绍Blueprint的使用. 一.Bean的配置 前面提到过,Ge ...

随机推荐

  1. JobScheduler android任务调度处理组件(类似QuartZ)

    JobScheduler是Android L(API21)新增的特性,用于定义满足某些条件下(电量,网络,时间,屏幕熄/亮 ,设备是否空闲 等)执行的任务.它的宗旨是把一些不是特别紧急的任务放到更合适 ...

  2. 用SpringSecurity从零搭建pc项目-01

    注:之前写过一些列的SpringSecurity的文章,重新写一遍是为了把某些不必要的步骤省去,留下精简的,因为工作中有一些不需要. 在java的权限框架里,shiro和SpringSecurity是 ...

  3. Spring Boot + Spring Cloud 实现权限管理系统 后端篇(二):数据库设计

    数据库设计 系统主要包含用户(sys_user).组织(sys_dept).角色(sys_role).菜单(sys_menu).角色组织(sys_role_dept).角色菜单(sys_role_me ...

  4. tensorflow 根据节点获取节点前的整张图

    1.先获取节点 output_layer = self.model.get_pooled_output() logits = self.tf_instance.matmul(output_layer, ...

  5. bigdata-02-hadoop2.8.4-resourceHA安装

    1, 电脑环境准备 1), 关闭selinux vim /etc/selinux/config SELINUX=disabled 2), 时间同步 yum -y install chrony 修改时间 ...

  6. Java实现排行榜基于Redis

    访问我的博客 前言 排行榜作为互联网应用中几乎必不可少的一个元素,其能够勾起人类自身对比的欲望,从而来增加商品的销量.排行榜的实现方式基本大同小异,大部分都基于 Redis 的有序集合 sorted ...

  7. Linq 多表连接查询join

    在查询语言中,通常需要使用联接操作.在 LINQ 中,可以通过 join 子句实现联接操作.join 子句可以将来自不同源序列,并且在对象模型中没有直接关系(数据库表之间没有关系)的元素相关联,唯一的 ...

  8. 【PyTorch深度学习60分钟快速入门 】Part0:系列介绍

      说明:本系列教程翻译自PyTorch官方教程<Deep Learning with PyTorch: A 60 Minute Blitz>,基于PyTorch 0.3.0.post4 ...

  9. 使用CSS定位元素实现水平垂直居中效果

    总结一下平时使用CSS技巧使元素达到水平居中效果 相对定位(或绝对定位)实现水平垂直居中: element{ position:relative; /*这个属性也可以是absolute*/ width ...

  10. C#Redis Sorted-Sets

    一.前戏 Sorted-Sets和Sets类型极为相似,它们都是字符串的集合,都不允许重复的成员出现在一个Set中.它们之间的主要差别是Sorted-Sets中的每一个成员都会有一个分数(score) ...