- 浏览: 1123559 次
- 性别:
- 来自: 火星郊区
博客专栏
-
OSGi
浏览量:0
文章分类
- 全部博客 (695)
- 项目管理 (48)
- OSGi (122)
- java (79)
- Vaadin (5)
- RAP (47)
- mysql (40)
- Maven (22)
- SVN (8)
- 孔雀鱼 (10)
- hibernate (9)
- spring (10)
- css (3)
- 年审 (6)
- ant (1)
- jdbc (3)
- FusionCharts (2)
- struts (4)
- 决策分析 (2)
- 生活 (10)
- 架构设计 (5)
- 破解 (2)
- 狼文化 (4)
- JVM (14)
- J2EE (1)
- 应用服务器 (1)
- 我的链接 (5)
- 数学 (2)
- 报表 (1)
- 百科 (6)
- Flex (7)
- log4j (2)
- PHP (1)
- 系统 (2)
- Web前端 (7)
- linux (6)
- Office (1)
- 安全管理 (5)
- python (2)
- dom4j (1)
- 工作流 (3)
- 养生保健 (4)
- Eclipse (8)
- 监控开发 (1)
- 设计 (3)
- CAS (1)
- ZK (41)
- BluePrint (3)
- 工具 (1)
- SWT (7)
- google (2)
- NIO (1)
- 企业文化 (2)
- Windoes (0)
- RCP (7)
- JavaScript (10)
- UML (1)
- 产品经理 (2)
- Velocity (10)
- C (1)
- 单元测试 (1)
- 设计模式 (2)
- 系统分析师 (2)
- 架构 (4)
- 面试 (2)
- 代码走查 (1)
- MongoDB (1)
- 企业流程优化 (1)
- 模式 (1)
- EJB (1)
- Jetty (1)
- Git (13)
- IPV6 (1)
- JQuery (8)
- SSH (1)
- mybatis (10)
- SiteMesh (2)
- JSTL (1)
- veloctiy (1)
- Spring MVC (1)
- struts2 (3)
- Servlet (1)
- 权限管理 (1)
- Java Mina (1)
- java 系统信息 (6)
- OSGi 基础 (3)
- html (1)
- spring--security (6)
- HTML5 (1)
- java爬虫搜索 (1)
- mvc (3)
最新评论
-
Tom.X:
http://osgia.com/
将web容器置于OSGi框架下进行web应用的开发 -
chenyuguxing:
你好, 为什么我的bundle export到felix工程中 ...
在Apache Felix中运行bundle -
string2020:
<niceManifest>true</ni ...
Bundle Plugin for Maven -
jsonmong:
OSGI,是未来的主流,目前已相当成熟。应用OSGI比较好的, ...
基于OSGi的声明式服务 -
zyhui98:
貌似是翻译过来的,有很少人在linux上做开发吧
如何成为“10倍效率”开发者
摘要:在进行Eclipse RCP开发的过程中,需要使用一些其他的资源(如图片、声音、配置文件、数据库等),我们一般将这些资源放到Plugin/Bundle的相应目录下(如 图片资源放到icons目录,声音放到sounds目录,数据库文件放到data目录)。本文先对Eclipse Plugin和Bundle进行分析,之后讲解了如何使用Eclipse API通过这些资源的相对路径(相对于Plugin/Bundle)获取这些资源的绝对路径的方法,最后总结了 org.osgi.framework.Bundle接口和FileLocator工具类的使用方法。
Bundle和Plugin
Eclipse Platform架构于OSGi核心之上,每个Eclipse Plugin就是OSGi的一个Bundle,因此在Eclipse RCP中Plugin和Bundle是等价的概念。
OSGi框架中定义了org.osgi.framework.IBundle接口,表示运行于OSGi环境中的一个Bundle。Eclipse RCP中定义了org.eclipse.core.runtime.Plugin抽象类,代表一个Eclipse插件。但是Plugin抽象类并没有实现 IBundle接口,而是在内部拥有一个IBundle对象实例。Plugin类实现了BundleActivator,控制其内部的IBundle对象 的启动和停止,并负责将BundleContext注入到IBundle对象实例中。
我们可以发现,在IBundle接口中定义了如下几个方法,可以获取位于在Bundle文件目录中的资源:
URL getResource(String name); | 通过Bundle的Class Loader加载资源,和Class.getResource(String)类似,注意如果当前的bundle是一个fregment,则返回null |
Enumeration getResources(String name) | 和上面的方法一样,不过由于Eclipse插件可以包括多个Fregment,每个Fregment中可以分别包含相对路径相同的文件,因此通过一个相对路径可能找到多个匹配的资源 |
URL getEntry(String path); | 在当前Bundle中根据Path找相应的Entry(此处的entry和resource到底有什么区别我还尚不清楚) |
Enumeration getEntryPaths(String path); | 和上面的方法一样,同getResources(String) |
Enumeration findEntries(String path, String filePattern, boolean recurse); |
根据path和pattern找相应的资源文件,可以使用通配符,如需要查找所有语言文件: bundle.findEntries(“OSGI-INF/l10n”, “*.properties”, true); |
如何获取当前的Bundle对象
开发Eclipse Plugin/Bundle应用首先需要创建Activator类,继承自 org.eclipse.ui.plugin.AbstractUIPlugin,该类继承自上文提到的 org.eclipse.core.runtime.Plugin类,OSGi框架在加载Plugin/Bundle的时候首先加载此Activator 类,然后调用此类中定义的start(BundleContext context)和stop(BundleContext context)方法启动和停止这个Plugin/Bundle。在这个类的父类Plugin中声明了Bundle类型实例,可以通过 getBundle()方法获取这个Bundle实例。
以下代码为Activator类中的start(BundleContext)方法,在其中调用了getResource(String)和 getEntry(String)两个方法,同时调用FileLocator.toFileURL(String)将URL转化为文件系统的路径
public void start(BundleContext context) throws Exception { super.start(context); plugin = this; System.out.println(Activator.getDefault().getBundle().getLocation()); URL url = Activator.getDefault().getBundle().getResource("META-INF/MANIFEST.MF"); System.out.println(url); System.out.println(FileLocator.toFileURL(url)); URL url2 = Activator.getDefault().getBundle().getEntry("META-INF/MANIFEST.MF"); System.out.println(url2); System.out.println(FileLocator.toFileURL(url2)); }
上面代码输出结果为:
bundleresource://709.fwk15218962:1/META-INF/MANIFEST.MF
file:/D:/demo/modeling-workspace/com.zhlwish.proppagedemo/META-INF/MANIFEST.MF
bundleentry://709.fwk15218962/META-INF/MANIFEST.MF
file:/D:/demo/modeling-workspace/com.zhlwish.proppagedemo/META-INF/MANIFEST.MF
通过结果可以很明显看到,使用getResource(String)和getEntry(String)获取到的URL是OSGi环境中的路径,需要通过FileLocator.toFileURL(String)方法将OSGi环境中的URL转化为文件系统中的URL。
至于getResource()和getEntry()有什么区别,我到Eclipse Forum里面提了问题,回答是:
- getResource uses the bundle’s class loader to load a resource. This resource could come from imported constraints (Import-Package, Require-Bundle) or from the local bundle classpath.
- getEntry only searches the bundles jar files itself and does not consider any constraints or the bundle’s class path (Bundle-ClassPath header).”
详见http://www.eclipse.org/forums/index.php/m/710032/#msg_710032
FileLocator
static URL find(Bundle bundle, IPath path, Map override); static URL find(URL url); static URL[] findEntries(Bundle bundle, IPath path); static URL[] findEntries(Bundle bundle, IPath path, Map override); static File getBundleFile(Bundle bundle); static InputStream openStream(Bundle bundle, IPath file, boolean substituteArgs); static URL resolve(URL url); static URL toFileURL(URL url);
看起来和Bundle中的方法那么的相似,归根结底,FileLocator中的方法也都是通过调用Bundle中的相对应方法来实现其功能的,除 了resolve(URL)和toFileURL(URL),后者之前演示过其功能,前者的功能也同样是将OSGi环境中的URL解析成为文件系统中的 URL。其实我不认为此FileLocator除去toFileURL()此方法外地其他方法有更好的地方,如果可能,还是直接用Bundle的方法更 好。
总结
很明显,在Bundle中查找文件资源需要通过FileLocator和Bundle两个类的协作才能完成,由于一般情况下Eclipse RCP的属性以及配置值存放于Eclipse Workspace中,从Bundle中读取资源的需求比较少。最主要的应用场景是,一些图片资源可以通过此方式读取,然后在Eclipse RCP应用中处理和显示。
发表评论
-
关于Felix Log Service
2012-12-07 16:44 1515OSGi服务纲要规范中定义了服务于OSGi平台的通用日志服 ... -
Maven 3 Felix 4 Eclipse 的搭建与部署(部分转载自别人文章)
2012-10-18 10:24 19924.1.开发环境搭建 4.2开发工具 Maven 3 F ... -
OpenCore:基于OSGi开发纯插件体系结构的WEB应用程序
2012-09-21 17:46 1376随着OSGi/Equinox逐渐成为Java EE服务端的基础 ... -
OSGi技术在Java Web开发中的应用
2012-09-20 11:26 1367随着 Java SE 对模块化功能原生支持的一再推迟(据最 ... -
OSGI典型的应用案例
2012-09-20 11:26 1570OSGI典型的应用案例主要有两个:分别是Eclipse和BMW ... -
OSGi特点
2012-09-20 11:26 12101、JRE版本无关性。虽然Java一直被人们认为是“Write ... -
OSGI与JMX 的关系
2012-09-19 17:09 1018不过重点是: JMX 本来设计的用途就只为了管理,我们不 ... -
在equinox环境开发web应用的"利器" -- registerResources()方法 详解
2012-09-19 17:07 1192registerResources()方法详解 1、简介 ... -
在equinox环境开发web应用的"利器" -- 序
2012-09-19 17:05 1325在equinox环境中开发web应用必须要借助一些工具包提供的 ... -
equinox环境下web应用资源的部署
2012-09-19 17:04 1268osgi的equinox实现环境下,web服务器和web应用都 ... -
OSGi产生的背景--在繁荣的混乱之中走出困惑
2012-09-19 16:58 1119软件的复杂性正在以惊 ... -
将web容器置于OSGi框架下进行web应用的开发
2012-09-16 14:26 3488将web容器置于OSGi框架下,其实就是将web容器做成OSG ... -
在Eclipse中开发OSGi Bundle
2012-09-16 14:26 1292Eclipse为开发OSGI Bundle提供了良好的支持,它 ... -
【第一代服务注册形式】 - 将一个Bundle注册为服务
2012-09-14 10:09 11091、创建业务接口类及其实现类 Java代码 ... -
Declarative Services规范简介及应用
2012-09-14 10:08 1372Declarative Services 是一 ... -
用FileInstall管理Bundle的动态安装、启动、卸载
2012-09-14 10:07 12971、文件目录如下: F:\study_osgi ... -
服务工厂 - Bundle消费者返回不同的服务对象
2012-09-14 10:03 1180一般情况下,服务对象在注册后,任何其它的Bundle在请求 ... -
服务跟踪(ServiceTracker)
2012-09-14 09:58 1127当多个Bundle使用同一 ... -
OSGi容器中Bundle之间Synchronous Communication
2012-09-11 17:07 1502OSGi Core定义了一个服务层,提供了一个Bundl ... -
OSGI 中嵌入 Http 服务器的运行环境
2012-07-31 13:44 3016Eclipse 4.2 OSGI 依赖的Bundle: or ...
相关推荐
OSGi捆绑包状态Maven插件 总览 OSGi容器的远程捆绑软件状态检查器。 请参阅以获取完整文档。 版本控制 遵循准则。
struts2-jasperreports-plugin-2.5.10.1.jar,struts2-javatemplates-plugin-2.5.10.1.jar,struts2-osgi-admin-bundle-2.5.10.1.jar,struts2-osgi-demo-bundle-2.5.10.1.jar,struts2-osgi-plugin-2.5.10.1.jar,...
maven编译pentaho-big-data-plugin遇到的所有问题解决,pentaho6.0
gradle-android-plugin.zip,用于Gradle构建系统的Android插件。用于Gradle构建系统的Android插件。
HOME] /project.extra.bundle,所以我们有[ROOT-HOME] /project.extra.bundle/plugin-1,[ROOT-HOME] /project.extra.bundle/plugin- 2 加Maven的第谷的支持,您的OSGi插件跟踪维基(添加第谷的支持)[ ] 编辑[ROOT-...
struts2-osgi-plugin-2.3.30.jar, struts2-oval-plugin-2.3.30.jar, struts2-pell-multipart-plugin-2.3.30.jar, struts2-plexus-plugin-2.3.30.jar, struts2-portlet-plugin-2.3.30.jar, struts2-rest-plugin-...
struts2-osgi-plugin-2.5.2.jar, struts2-oval-plugin-2.5.2.jar, struts2-pell-multipart-plugin-2.5.2.jar, struts2-plexus-plugin-2.5.2.jar, struts2-portlet-plugin-2.5.2.jar, struts2-rest-plugin-2.5.2.jar,...
maven-bundle-plugin-1.0.0.jar maven-clean-plugin-2.4.1.jar maven-clean-plugin-2.5.jar maven-common-artifact-filters-1.3.jar maven-compat-3.2.1-sources.jar maven-compiler-plugin-2.5.1.jar maven-...
struts2-osgi-admin-bundle-2.5.10.jar,struts2-osgi-demo-bundle-2.5.10.jar,struts2-osgi-plugin-2.5.10.jar,struts2-oval-plugin-2.5.10.jar,struts2-pell-multipart-plugin-2.5.10.jar,struts2-plexus-plugin-...
gradle-bundle-plugin.zip,生成osgi包的gradle插件。
osgi文章中用到的所有依赖jar,资源分不够用了,1积分下载后回复下就可以了
OrbisGIS 4.0 OSGI插件包的Maven...OrbisGIS OSGi SQL Bundle Artchetype osgi-sql包含用于编写您自己SQL函数并将其作为新服务公开的原型。 OrbisGIS将注意到该用户定义SQL函数,并将其添加到当前的GDMS SQL引擎中。
该插件允许创建 apache felix 框架安装以准备运行 osgi bundle 应用程序。 特征 Felix Launcher 插件的特点: 下载所需的 apache felix 框架包 felix 框架的配置、组装和执行 将自定义包编译并包含到 felix 框架中...
struts2-osgi-plugin-2.3.15.3.jar struts2-oval-plugin-2.3.15.3.jar struts2-pell-multipart-plugin-2.3.15.3.jar struts2-plexus-plugin-2.3.15.3.jar struts2-portlet-plugin-2.3.15.3.jar struts2-rest-plugin-...
AEM 示例项目 此示例项目展示了典型 AEM 项目的 maven 设置可能是什么样子。 主要关注的是 maven 插件的使用以及继承可选的构建配置文件installBundle和installPackage 。...| | +- pom.xml # an OSGi bundle that c
参照网上的示例自己做的,主要是webapp这个bundle,可以运行
要安装Jekyll,请参阅 安装Jekyll后,您可以使用以下网站构建网站: bundle exec jekyll serve此命令将构建网站并在上启动本地Jekyll服务器注意:您本地的Jekyll安装可能需要Apache Karaf网站所需的其他模块。...