很多Java程序员对Eclipse(日食,IBM起这个名字,Sun大概有意见)都爱不释手,在JBuilder流行、主流内存配置还在256M的日子里,当我第一次成功运行Eclipse后就把JBuilder彻底请出了我的电脑硬盘。不错,这就是Elipse的魅力。
作为程序员在感受Eclipse带来诸多好处之后,强烈的好奇心驱使我在问:Eclipse的魅力从何而来。正如我们谈论一个美女为什么那么美一样,造成美的因素是多方面的(上次的人物访谈说节目中说:周迅是美女,有个摄影家还用尺子量周迅鼻子到下巴的距离来证明)。在Eclipse令人称道的很多因素中,其开放性的插件架构无疑是最浓重的一笔。
为Eclipse开发一个插件并没有想象中的那么复杂,使用Eclipse的Rich Client Platform开发自己的软件界面也很容易上手。为Elipse带来如此魔力的就是:Equinox(月食)(http://eclipse.org/equinox)。本文的题目还有一个OSGi,OSGi和Equinox的关系是什么呢?说来话长,简单的理解,相当于JBoss和Ejb specification的关系,或者Tomcat和Servlet Specification的关系。
OSGi中的一个核心概念是:bundles。
对于Equinox来说,bundles就是一个自描述型的jar文件,描述如下:
Bundle-SymbolicName: org.eclipse.equinox.registry Bundle-Version: 3.2.100.v20060918 Bundle-Name: Eclipse Extension Registry Bundle-Vendor: Eclipse.org Bundle-ClassPath: . Bundle-Activator: org.eclipse.core.internal.registry.osgi.Activator Export-Package: org.eclipse.equinox.registry Import-Package: javax.xml.parsers, org.xml.sax, org.osgi.framework;version=1.3 Require-Bundle: org.eclipse.equinox.common;bundle-version="[3.2.0,4.0.0)" Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0,J2SE-1.3
如果单纯作为一个插件机制,尽管Equinox解决方法很棒,但并没有什么过人之处,最让我感到惊奇的是他的“包容”能力。原文一句话说的好:“There are two main approaches; embedding Equinox in the servlet container or embedding the servlet container in Equinox”。
Bundle-SymbolicName: org.eclipse.equinox.registry Bundle-Version: 3.2.100.v20060918 Bundle-Name: Eclipse Extension Registry Bundle-Vendor: Eclipse.org Bundle-ClassPath: . Bundle-Activator: org.eclipse.core.internal.registry.osgi.Activator Export-Package: org.eclipse.equinox.registry Import-Package: javax.xml.parsers, org.xml.sax, org.osgi.framework;version=1.3 Require-Bundle: org.eclipse.equinox.common;bundle-version="[3.2.0,4.0.0)" Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0,J2SE-1.3
看看下面这3个图吧:
Figure 1: Traditional web application server structure
Figure 2: Embedding Equinox in an existing application container
来源链接:http://tb.blog.csdn.net/TrackBack.aspx?PostId=1475050
(责任编辑 火凤凰 sunsj@51cto.comTEL:(010)68476636-8007)