- 浏览: 1149381 次
- 性别:
- 来自: 火星郊区
博客专栏
-
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倍效率”开发者
Small Talks/2012/March/Develop ZK application in OSGi Framework
-
Author
- Vincent Jian, Engineer, Potix Corporation
-
Date
- March 13, 2012
-
Version
- ZK 5
Contents[hide ] |
Introduction
OSGi-supported framework allows developers to develop appliactions in a modularized environment for ease of management and version control.
A few weeks ago Erko Knoll has shared an example on using ZK in OSGi environment. Now this small talk will demonstrate in detail how you can convert ZK jars into an OSGi bundle and how you can use this bundle to develop an OSGi-supported application.
If you are not familiar with OSGi it is recommended to read Erko's article [1] first before reading this small talk.
Convert ZK jars into an OSGi Bundle
An OSGi Bundle is actually a jar file that contains MANIFEST.MS file under META-INF folder. The file describes the bundle with various attributes (Bundle-Name, Bundle-SymbolicName, Bundle-Version, Export-Package, Import-Package, and etc.) as the following example:
1
2
3
4
5
6
7
8
9
10
11
|
Manifest-Version:
1.0
Bundle-ManifestVersion:
2
Bundle-Name: OSGi Demo
Bundle-SymbolicName: osgi.demo;
Bundle-Version:
1.0
Bundle-RequiredExecutionEnvironment: J2SE-
1.5
Require-Bundle: other-bundle-name;bundle-version=
"1.0"
Export-Package: business.service,
model.pojo
Import-Package: javax.servlet;version=
"2.5.0"
,
javax.servlet.http;version=
"2.5.0"
|
However, to manually prepare this file, especially adding Export-Package and Import-Package of ZK jars in MANIFEST.MS is a time consuming job. Here we would like to introduce two methods to convert ZK jars into one OSGi Bundle with the assist of Eclipse IDE. The first method is to use Eclipse Plug-in Project, and the second method is to use BND.
Eclipse Plug-in Project
Follow the steps to create a ZK OSGi bundle:
- Follow Eclipse Wizard to create a new Plug-in Project.
- File -> New -> Other -> Plug-in Project
- Type the project name (here I use zkee.osgi.bundle ) and in Target Platform choose an OSGi framework as standard , press Next button.
- In Properties panel, type ID (zkee.osgi.bundle ), Version (latest ZK release version, 5.0.10 ), Name (ZK EE OSGi Bundle ) and Provider (leave blank) information, and the Execution Environment choose J2SE-1.5 for compatibility. In Options panel, unchecked Generate an activator since we do not need Activator here. Press Next button
- Unchecked Create a plug-in using one of the templates since we do not need it here. Press Finish button.
- Create lib
folder under the project and copy all ZK EE
jars (in this case we are using EE edition) in the lib folder. The jars
under ext and zkforge folders should also be moved to the lib folder.
- Open MANIFEST.MF
file to modify the OSGi Bundle attributes
- Click Runtime
tab. In Classpath panel, add all jars in
lib folder. In Export Packages add all packages that zk jars provided,
include non-java packages.
- The Export Packages will miss "web.WEB-INF.tld.web
" and "web.WEB-INF.tld.zk
" that have to added manually in MANIFEST.MF
tab.
- Go back the Runtime tab, in Export Package panel, click Calculate Uses to analyze the package usage. This operation will take almost an half hour or more to finish ( you can remove the jars you don't need to speed it up).
- Click Dependencies
tab. In Imported Packages
panel, add necessary import package here. Depending on the OSGi
container you are using, the required import packages may be different.
Here are the minimum required packages:
- javax.servlet;version="2.5.0"
- javax.servlet.http;version="2.5.0"
- javax.swing.filechooser
- javax.xml.parsers
- javax.xml.transform
- javax.xml.transform.dom
- javax.xml.transform.stream
- org.w3c.dom
- org.xml.sax
- org.xml.sax.ext
- org.xml.sax.helpers
- Click Runtime
tab. In Classpath panel, add all jars in
lib folder. In Export Packages add all packages that zk jars provided,
include non-java packages.
- Export the bundle in Overview tab by Export Wizard button located at bottom right, and the bundle is ready.
BND
Another option is to use BND. BND tool is developed by Peter Kriens that can help to create an OSGi bundle and convert existed JAR files into OSGi bundle easily. Here we will show how we can use the Eclipse plug-in BndTools to convert ZK jars into an OSGi bundle. The steps are as follows,
- Install BndTools plug-in
- Open Eclipse, Help -> Eclipse Marketplace -> Find "BndTools" -> Install
- Create Bnd project
- File -> New -> Other -> BndTools -> Wrap JAR as OSGi Bundle Project -> Add External
- Follow the wizard to type the Project Name
and choose J2SE-1.5
for compatibility. After finishing the wizard, Eclipse will change the view to Bundle content as the following image.
- Click the Contents
tab then type the Version info and save the changes.
- Check the generated jar, and that is the OSGi bundle we want.
- Repeat step 2 for all ZK jars.
- Here you can copy all the generated jars into the repository of the OSGi container, or
- Wrap all the generated jars into one OSGi bundle by Eclipse Plug-in Project described above without the Calculate Uses step.Note : this option is recommended for ease of use.
With BndTools, we can convert ZK jars into OSGi bundle quickly, and it will prepare import packages automatically, where with Eclipse Plug-in Project we need to specify import packages by ourselves. However, one thing to note is that with BndTools we have to wrap ZK jar files one by one because the Export Packages are duplicate due to duplicated package name, such as metainfo.zk .
Develop ZK Application
In the previous section, we have converted ZK jars into one OSGi bundle. Here we will show how we can use this bundle to develop an OSGi-supported ZK application - a modularized simple CRUD application.
Basic module design
Normally, we create an ZK application with MVC pattern where we will put the data access related classes in one package and the web view related classes in another. And in the case that we need a different web view with same back-end data set we will create another web project and copy the same data access code from the first project.
With OSGi's modular concept, we don't need to copy and paste as what we used to do. We can simply draw the data access code into a standalone OSGi bundle called Data Access Bundle, and both the two web view bundles can use this data access code by defining Require-Bundle in MANIFEST.MF . Here is an image that illustrates the concept:
Data Access Bundle
The data access bundle is a simple plug-in project that contains POJO beans, DAO classes and Service classes. Here are the steps to create data access bundle:
- Create Plug-in Project by Eclipse wizard, the project name here I use is osgi.demo.data .
- Create packages, and write related code
- Modify MANIFEST.MS file. Since only Manager class and POJO beans will be used in Web View, the requested Export-Package are business.service and model.pojo
- The final project structure:
- Export the project by Eclipse Deployable plug-ins and fragments wizard.
1
2
3
4
5
6
7
8
|
Manifest-Version:
1.0
Bundle-ManifestVersion:
2
Bundle-Name: Data Access Bundle
Bundle-SymbolicName: osgi.demo.data
Bundle-Version:
1.0
.
0
Bundle-RequiredExecutionEnvironment: J2SE-
1.5
Export-Package: business.service,
model.pojo
|
Web View Bundle
The web view bundle is also a plug-in project that requires ZK OSGi bundle generated before and the data access bundle to present data. Here are the steps to create web view bundle project:
- Create Plug-in Project by Eclipse wizard, the project name here I use is osgi.demo.webview.
- Create WEB-INF folder under project root that contains web.xml and zk.xml as usual.
- Create index.zul under project root and write necessary Composer class
- Modify MANIFEST.MF file as follow. In line 7 and 8, we define required bundle based on the ZK components and POJO bean required for presenting data. Please notice line 9, with the Web-ContextPath[2] attribute defined here, the OSGi container will recognize that this bundle will run as a web application. And the web url will be http://localhost:port/osgidemo
- Modify build.properties file as follow. The WEB-INF folder, zul files and any other folder you created must be checked here.
- The final project structure:
- Export the project by Eclipse Deployable plug-ins and fragments wizard.
1
2
3
4
5
6
7
8
9
10
|
Manifest-Version:
1.0
Bundle-ManifestVersion:
2
Bundle-Name: Web View Bundle
Bundle-SymbolicName: osgi.demo.webview;singleton:=
true
Bundle-Version:
1.0
.
0
Bundle-RequiredExecutionEnvironment: J2SE-
1.5
Require-Bundle: zkee-osgi;bundle-version=
"5.0.10"
,
osgi.demo.data;bundle-version=
"1.0.0"
Web-ContextPath: /osgidemo
Webapp-Context: /osgidemo
|
Deploy to OSGi Container
In the previous section, we have modularized the project into two bundles. Here we will deploy these bundles in OSGi container and this is the last step. There are many OSGi containers available out there, and I have tried with the following three containers, Eclipse Equinox, Apache ServiceMix, and EclipseRT Virgo.
Eclipse Equinox
Eclipse Equinox [3] is an implementation of the OSGi R4 core framework specification, a set of bundles that implement various optional OSGi services and other infrastructure for running OSGi-based systems.
Steps to deploy the project
There is no need to deploy or to export the project with Eclipse Equinox, you can see the result instantly during development phase by EclipseRTWebStarterKit. Here are the steps that demonstrate how to use EclipseRTWebStarterKit in Eclipse IDE.
- Download EclipseRTWebStarterKit ready-to-run server package here and unzip the file.
- Import EclipseRTWebStarterKit to Eclipse workspace.
- File -> Import -> General -> Existing Projects into Workspace
- Open EclipseRTWebStartkerKit.target under project root, then click Set as Target Platform link.
- Right click the osgi.demo.webview
project -> Run -> Run Configuration... -> OSGi Framework
- In order to make sure the bundle start sequence, set the start level in Bundles tab.
- Add additional VM arguments In the (x)= Arguments tab.
- Click Run
button
- In the Eclipse Console it will show osgi console. You can Type "help" command to show the command list and usage.
- In the osgi console type "ss" command, if you see all bundle is INSTALLED status. Close the console and then re-run OSGi framework again.
- Visit http://localhost:8080/osgidemo/index.zul to see the result.
- You can keep changing the code without terminating OSGi framework, just type "restart BundleID" in osgi console to see the changes.
Apache ServiceMix
Apache ServiceMix [4] is a flexible, open-source integration container that unifies the features and functionality of Apache ActiveMQ , Camel , CXF , ODE , Karaf into a powerful runtime platform you can use to build your own integrations solutions. It provides a complete, enterprise ready ESB (enterprise service bus) exclusively powered by OSGi.
Steps to deploy the project
- Download Apache ServiceMix from http://servicemix.apache.org/ and unzip the file to "C:\apache-servicemix-4.4.0".
- Copy the three bundles (zkee-osgi_5.0.10.jar, osgi.demo.data_1.0.0.jar and osgi.demo.webview_1.0.0.jar) into "C:\apache-servicemix-4.4.0\deploy"
- Execute "C:\apache-servicemix-4.4.0\bin\servicemix.bat" file in command line.
- Visit http://localhost:8181/osgidemo/index.zul to see the result.
-
Note
: if you cannot see the correct result, it might be
caused by the wrong bundle installation sequence. You can try to use the
following command to fix the problem.
- Find the webview bundle ID:
- Restart the bundle:
1
|
web:list
|
1
|
osgi:restart BundleID
|
EclipseRT Virgo
The Virgo Web Server from EclipseRT is a completely module-based Java application server that is designed to run enterprise Java applications and Spring-powered applications with a high degree of flexibility and reliability. It offers a simple yet comprehensive platform to develop, deploy, and service enterprise Java applications.[5]
Steps to deploy the project
- Download EclipseRT Virgo from http://eclipse.org/virgo/download/ .
- Follow the user guide to install and start the server.
- Open the Web Admin Console via http://localhost:8080/admin with default account/password(admin/springsource)
- Follow the bundle installation guide here
- Deploy the three bundles one by one with the following sequence.
- zkee-osgi_5.0.10.jar
- osgi.demo.data_1.0.0.jar
- osgi.demo.webview_1.0.0.jar
- Visit http://localhost:8080/osgidemo/index.zul to see the result.
Conclusion
The OSGi standard provides powerful modularization and version control which I think is very convenient for developers to control the bundle versions with various functions, and can help developers to design the skeleton of the project with loose coupling. Also it reduces the time for restarting the server during development phase. Following this article you should be able to convert ZK jar files into OSGi bundles and start your first OSGi-supported application.
Download
Download the sample bundles:
Reference
- ↑ Erko Knoll's article: Small_Talks/2011/December/ZK_OSGi_-_Developing_plug-in_based_applications_with_OSGi
- ↑ Some OSGi containers will read Webapp-Context attribute instead of reading standard Web-ContextPath attribute so here we define both attributes for compatibility.
- ↑ Eclipse Equinox: http://eclipse.org/equinox/ Eclipse
- ↑ Apache ServiceMix: http://servicemix.apache.org/
- ↑ EclipseRT Virgo: http://eclipse.org/virgo/
发表评论
-
关于Felix Log Service
2012-12-07 16:44 1567OSGi服务纲要规范中定义了服务于OSGi平台的通用日志服 ... -
Maven 3 Felix 4 Eclipse 的搭建与部署(部分转载自别人文章)
2012-10-18 10:24 20334.1.开发环境搭建 4.2开发工具 Maven 3 F ... -
【绝对路径】OSGi环境中获取Plugin/Bundle中文件资源的绝对路径
2012-10-08 10:53 2492摘要:在进行Eclipse RCP开发的过程中,需要使用一 ... -
OpenCore:基于OSGi开发纯插件体系结构的WEB应用程序
2012-09-21 17:46 1423随着OSGi/Equinox逐渐成为Java EE服务端的基础 ... -
OSGi技术在Java Web开发中的应用
2012-09-20 11:26 1411随着 Java SE 对模块化功能原生支持的一再推迟(据最 ... -
OSGI典型的应用案例
2012-09-20 11:26 1634OSGI典型的应用案例主要有两个:分别是Eclipse和BMW ... -
OSGi特点
2012-09-20 11:26 12491、JRE版本无关性。虽然Java一直被人们认为是“Write ... -
OSGI与JMX 的关系
2012-09-19 17:09 1058不过重点是: JMX 本来设计的用途就只为了管理,我们不 ... -
在equinox环境开发web应用的"利器" -- registerResources()方法 详解
2012-09-19 17:07 1227registerResources()方法详解 1、简介 ... -
在equinox环境开发web应用的"利器" -- 序
2012-09-19 17:05 1363在equinox环境中开发web应用必须要借助一些工具包提供的 ... -
equinox环境下web应用资源的部署
2012-09-19 17:04 1307osgi的equinox实现环境下,web服务器和web应用都 ... -
OSGi产生的背景--在繁荣的混乱之中走出困惑
2012-09-19 16:58 1165软件的复杂性正在以惊 ... -
将web容器置于OSGi框架下进行web应用的开发
2012-09-16 14:26 3539将web容器置于OSGi框架下,其实就是将web容器做成OSG ... -
在Eclipse中开发OSGi Bundle
2012-09-16 14:26 1330Eclipse为开发OSGI Bundle提供了良好的支持,它 ... -
【第一代服务注册形式】 - 将一个Bundle注册为服务
2012-09-14 10:09 11551、创建业务接口类及其实现类 Java代码 ... -
Declarative Services规范简介及应用
2012-09-14 10:08 1421Declarative Services 是一 ... -
用FileInstall管理Bundle的动态安装、启动、卸载
2012-09-14 10:07 13331、文件目录如下: F:\study_osgi ... -
服务工厂 - Bundle消费者返回不同的服务对象
2012-09-14 10:03 1207一般情况下,服务对象在注册后,任何其它的Bundle在请求 ... -
服务跟踪(ServiceTracker)
2012-09-14 09:58 1159当多个Bundle使用同一 ... -
OSGi容器中Bundle之间Synchronous Communication
2012-09-11 17:07 1560OSGi Core定义了一个服务层,提供了一个Bundl ...
相关推荐
文件"zkpe-bin-osgi-eval-6.5.1-FL-2012-09-14"可能是指ZK的OSGI版本,OSGI(Open Services Gateway Initiative)是一种模块化系统,用于Java应用程序的动态管理和部署。ZK集成OSGI,意味着开发者可以灵活地组合和...
平台的核心理念是采用组件化和模块化的开发模式,借助OSGI技术实现组件的复用和动态部署,以提升软件企业的创新能力和市场竞争力。 首先,企业信息化应用平台的建立是软件企业发展的重要战略,它可以整合各种业务...
它以 jar 的形式发布,部署容易,使用也较为便捷。 Java邮箱地址验证 jaev jaev 是一个用来验证电子邮箱地址是否有效的 Java 项目。 Java的FastCGI网关 jFastCGI jFastCGI 是一个可以让Tomcat 之类的Servlet容器...
它以 jar 的形式发布,部署容易,使用也较为便捷。 Java邮箱地址验证 jaev jaev 是一个用来验证电子邮箱地址是否有效的 Java 项目。 Java的FastCGI网关 jFastCGI jFastCGI 是一个可以让Tomcat 之类的Servlet容器...
它以 jar 的形式发布,部署容易,使用也较为便捷。 Java邮箱地址验证 jaev jaev 是一个用来验证电子邮箱地址是否有效的 Java 项目。 Java的FastCGI网关 jFastCGI jFastCGI 是一个可以让Tomcat 之类的Servlet容器...
它以 jar 的形式发布,部署容易,使用也较为便捷。 Java邮箱地址验证 jaev jaev 是一个用来验证电子邮箱地址是否有效的 Java 项目。 Java的FastCGI网关 jFastCGI jFastCGI 是一个可以让Tomcat 之类的Servlet容器...
它以 jar 的形式发布,部署容易,使用也较为便捷。 Java邮箱地址验证 jaev jaev 是一个用来验证电子邮箱地址是否有效的 Java 项目。 Java的FastCGI网关 jFastCGI jFastCGI 是一个可以让Tomcat 之类的Servlet容器...
它以 jar 的形式发布,部署容易,使用也较为便捷。 Java邮箱地址验证 jaev jaev 是一个用来验证电子邮箱地址是否有效的 Java 项目。 Java的FastCGI网关 jFastCGI jFastCGI 是一个可以让Tomcat 之类的Servlet容器...
它以 jar 的形式发布,部署容易,使用也较为便捷。 Java邮箱地址验证 jaev jaev 是一个用来验证电子邮箱地址是否有效的 Java 项目。 Java的FastCGI网关 jFastCGI jFastCGI 是一个可以让Tomcat 之类的Servlet容器...
它以 jar 的形式发布,部署容易,使用也较为便捷。 Java邮箱地址验证 jaev jaev 是一个用来验证电子邮箱地址是否有效的 Java 项目。 Java的FastCGI网关 jFastCGI jFastCGI 是一个可以让Tomcat 之类的Servlet容器...
它以 jar 的形式发布,部署容易,使用也较为便捷。 Java邮箱地址验证 jaev jaev 是一个用来验证电子邮箱地址是否有效的 Java 项目。 Java的FastCGI网关 jFastCGI jFastCGI 是一个可以让Tomcat 之类的Servlet容器...
它以 jar 的形式发布,部署容易,使用也较为便捷。 Java邮箱地址验证 jaev jaev 是一个用来验证电子邮箱地址是否有效的 Java 项目。 Java的FastCGI网关 jFastCGI jFastCGI 是一个可以让Tomcat 之类的Servlet容器...
它以 jar 的形式发布,部署容易,使用也较为便捷。 Java邮箱地址验证 jaev jaev 是一个用来验证电子邮箱地址是否有效的 Java 项目。 Java的FastCGI网关 jFastCGI jFastCGI 是一个可以让Tomcat 之类的Servlet容器...
它以 jar 的形式发布,部署容易,使用也较为便捷。 Java邮箱地址验证 jaev jaev 是一个用来验证电子邮箱地址是否有效的 Java 项目。 Java的FastCGI网关 jFastCGI jFastCGI 是一个可以让Tomcat 之类的Servlet容器...
它以 jar 的形式发布,部署容易,使用也较为便捷。 Java邮箱地址验证 jaev jaev 是一个用来验证电子邮箱地址是否有效的 Java 项目。 Java的FastCGI网关 jFastCGI jFastCGI 是一个可以让Tomcat 之类的Servlet容器...
Java访问权限控制源代码 1个目标文件 摘要:Java源码,文件操作,权限控制 Java访问权限控制,为Java操作文件、写入文件分配合适的权限,定义写到文件的信息、定义文件,输出到c:/hello.txt、写信息到文件、关闭输出流...