首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

eclipse上Jetty Plugin的开发应用

2012-11-04 
eclipse下Jetty Plugin的开发应用Jetty做为一个轻量级的J2EE Web application server,它不仅小巧,而且性能

eclipse下Jetty Plugin的开发应用
Jetty做为一个轻量级的J2EE Web application server,它不仅小巧,而且性能也比较稳定,效率也挺高,现在也越来越得到广泛的应用。特别是eclipse平台集成了Jetty Plugin后,更是对RCP整合Web Server开发提供了极大的方便。一个非常典型的应用应该就是help帮助系统了,大家可以参看eclipse自已的help系统,从3.3后它就是基于Jetty的,现在的Jetty版本是5.1。

在这里不得不先叉开一个话题,就是servlet-bridge桥的概念。Jetty只是一个单纯的web server服务器,eclipse为了整合框架的考虑,提出了servlet-bridge的概念,对Jetty进行了封装,提供了基于Extension point的servlet注册机制。用户只需要在plugin.xml文件中对相应的Extension point进行扩展,就可以很方便将一个servlet注册到web server上。也就是说,标准的J2EE应用,我们需要一个web.xml文件对所有的servlet,context-param等等进行配置说明;现在这些都基于eclipse http registry所提供的Extension point进行注册,不再需要web.xml文件。

下面,我们看一个plugin.xml的例子。
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin>
   <extension
         point="org.eclipse.equinox.http.registry.httpcontexts">
      <httpcontext
            id="myapp">           
         <resource-mapping
               path="/myapp">
         </resource-mapping>
      </httpcontext>
   </extension>
   <extension
         point="org.eclipse.equinox.http.registry.resources">
      <resource
            alias="/"
            base-name="/"
            httpcontextId="myapp">
      </resource>
      <serviceSelector
            filter="(other.info=org.myapp.jetty.demo)">
      </serviceSelector>
   </extension>
   <extension
         point="org.eclipse.equinox.http.registry.servlets">
      <servlet
         alias="/myfirstservlet"
         + webappName ); //$NON-NLS-1$ //$NON-NLS-2$ dict.put( "other.info", pluginID ); //$NON-NLS-1$ // Startup Jetty web server JettyConfigurator.startServer( webappName, dict ); ensureBundleStarted( "org.eclipse.equinox.http.registry" ); //$NON-NLS-1$

停止一个Web application,一句代码就够了:

JettyConfigurator.stopServer( webappName );


附件中是我写的一个示例plugin,包含了所有基本的功能。包括启动/停止一个web application,注册servlet,JSP文件示例等等。

大家可以很方便的应用到自已开发的RCP应用中去。
~_~

1 楼 caixicai 2008-12-05   hello,楼主。
我想知道一下,你知道有支持jetty7的 eclipse 插件麽 2 楼 cyfgod 2008-12-05   caixicai 写道
hello,楼主。 我想知道一下,你知道有支持jetty7的 eclipse 插件麽

最新的eclipse3.5里还是旧的Jetty 5.1版本。
或者你可以试试Jettylauncher。

热点排行