随笔 - 1  文章 - 37  trackbacks - 0
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

留言簿(16)

随笔分类

随笔档案

文章分类

文章档案

test

搜索

  •  

最新评论

关于作者

      The author of this article is co-author of the book "Struts Best Practices" published in German (2004) and French (Feb 2005). He has been working with Java n-tier web since 1998, including SilverStream appserver, before the advent of OS and J2EE. His company, Infonoia SA is editor of multi-platform, multi-repository software and solutions around document retrieval and publishing. Infonoia also provides consulting services, mentoring and training (English, French, German) on Best Practices in the web technologies and frameworks they use, such as Struts, Eclipse and RSP. Wolfgang is also available for speaking engagements on RSP. Wolfgang can be reached at wgehner at infonoia dot com.

一、关于这篇文章

      这篇文章将会分成两个部分通过分析一个实例去分析如果使用OSGI构建一个WEB应用。
        第一个部分只是简单的介绍了如何在应用中创建扩展点(extension points),第二部分将通过映射你自己的Servlet和依赖关系使其能够作为一个新的Web应用运行

二、准备工作

      1. jdk, 最好将1.5和1.6都准备好,因为下一篇文章将会用到jdk1.6
      2. Eclipse 3.3
      3.下载本文中需要用到的示例应用包,[
下载地址]

三、运行这个应用

      1. 将Rspdemo-0.2.zip解压到C盘,形成目录 C:\rsp
      2. 双击 C:\rsp\t.bat ,启动 Tomcat ,你也可以去 C:\rsp\apache-tomcat-5.5.15\bin里面启动,效果都一样,它里面的Tomcat几乎是原装的
      3.打开浏览器,访问
http://localhost/rspwebapp ,你应该会看到这个效果


OK,去 http://localhost/rspwebapp/struts.jsp 这个页面看看,这个页面是由Struts模块生成的



这个页面的功能自己尝试一下就知道了


四、尝试修改应用代码
1.将Eclipse3.3解压缩(覆盖)到 C:\rsp\eclipse (由于原文件夹内包含Workspace和Project相关信息,所以不建议删除原eclipse文件夹),接着运行Eclipse,Workspace默认就行了,在[Package Explorer]面板里就会有3个Working Set,里面都是Plug-in Project,也就是传说中的Bundle了。
注:你可能会发现所有的[MANIFEST.MF]几乎都有错误提示,原因可能是这个Web应用是在Linux/Unix操作系统写的导致Eclipse的Editer无法识别该格式(JAVA文件也是如此),所以只需要用Text Editor打开一次该文件,让Eclipse自动改变文件格式就行了。

2. 展开所有Project,打开org.rsp.sample.usage.servlet.MyServlet,修改一下doGet()方法,加入一些能在页面上显示的东西


3. 用 Plug-in Manifest Editor 打开 MANIFEST.MF, 使用Overview面板中的Export Wizard,将这个插件输出到独立Jar包(默认设置)


4. 访问  http://localhost/rspwebapp/platform/sp_redeploy  页面重新部署插件,然后再访问 http://localhost/rspwebapp,页面中多了
--------- Hello, Phrancol ! ---------

这3个Working set包含的内容:
Equinox - 简单的说,就是OSGI的运行环境。
Rsp samples - Web application的内容,包括配置文件,资源文件等。
Simplejars - Rsp samples里面所需要的Jar包,每个jar包都被作为一个独立的Plug-in.

五、Web application的目录结构
org.rsp.sample.webapp实际上就是一个web应用,可以在C:\rsp\apache-tomcat-5.5.15\conf\Catalina\localhost里面找到Context的配置文件。
在WebContent/WEB-INF/web.xml里面配置Equinox的servletbridge启动OSGI运行环境。
进入C:\rsp\workspace\org.rsp.sample.webapp\WebContent\WEB-INF\platform目录,发现里面的目录结构几乎与Eclipse的目录结构一样,
这几个目录的用处:

configuration - 里面默认的 config.ini 列出所有可用的bundle,和他们的启动级别,Equinox将自动读取这个配置文件启动bundles
plugins - bundle都放在这里面
links - 与Eclipse里面的links目录作用一样,读取外部bundle

Eclipse的网站上有Equinox更详细的介绍和简单的示例 [点击这里]
注意:这个示例中使用的Equinox应该是较老的版本,最新的版本对目录结构和bridge实现都有更好的改进,可以在Eclipse的CVS上获取最新的Equinox代码

六、访问其他bundle
打开org.rsp.sample.webapp/WebContent/struts.jsp,能看到<c:import url="/platform/do/myAct" />,也就是http://localhost/rspwebapp/platform/do/myAct ,这个页面是由 org.rsp.framework.struts 提供的,打开它里面的 plugin.xml,可以发现
这样一段配置
    <extension id="myservletID" name="myservletName" point="org.eclipse.equinox.servlet.ext.servlets">
        
<alias>/do</alias>
        
<servlet-class>org.rsp.framework.struts.base.BundleActionServlet</servlet-class>
        
<init-param>
            
<param-name>config</param-name>
            
<param-value>*/WEB-INF/struts-config.xml</param-value>            
        
</init-param>        
        
<init-param>
            
<param-name>chainConfig</param-name>
            
<param-value>*/WEB-INF/chain-config.xml</param-value>            
        
</init-param>
        
<httpcontext-name>cross-context</httpcontext-name>
    
</extension>

里面就是关于 Extension 和 Extension points 的相关配置,在Equinox上有更详细的介绍,于是大概能理解这个页面是如何来的了,也大概能理解如何使用其他bundle的资源。


结束语

偶尔从Google上搜索到了这篇文章,感觉对像我这样的OSGI初学者很有用,于是将其意思整理了一下,帖在BLOG上,希望能对路过的OSGI爱好者有所帮助。
如果想更好的理解作者的意图,建议看原文。
欢迎大家通过邮箱osgi.phrancol@gmail.com与我讨论有关OSGI的话题。

Developing Eclipse/OSGi Web Applications Part 1 
Developing Eclipse/OSGi Web Applications Part 2
Equinox in a Servlet Container
posted on 2007-08-29 22:40 Phrancol Yang 阅读(3659) 评论(1)  编辑  收藏 所属分类: OSGI

FeedBack:
# re: 开发基于Equinox/OSGI 的 Web Application (一) [译] 2007-09-11 17:09 man
不错!!!...... 比码英文爽多了....
  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: