成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Equinox OSGi服務器應用程序的配置步驟

開發 后端
在Eclipse里如何配置一個簡單的基于Eclipse Equinox OSGi實現的Web應用程序,在它的基礎上可以構造更加復雜的應用,本文使用的是Eclipse 3.3.1版本,如果你的Eclipse版本在3.2.0或以上應該都可以。

本文介紹在Eclipse里如何配置一個簡單的基于Eclipse Equinox OSGi實現的Web應用程序,在它的基礎上可以構造更加復雜的應用,本文使用的是Eclipse 3.3.1版本,如果你的Eclipse版本在3.2.0或以上應該都可以。

51CTO編輯推薦:OSGi入門與實踐全攻略

一、支持靜態頁面和Servlet

1. 創建一個新的plugin項目, net.bjzhanghao.osgi.test,在向導***步里選中“This plug-in is target,在下一步的“Plug-in Options”里選中“Generate an activator”。

 


2. 在例子項目的MANIFEST.MF里添加如下依賴項目,這些項目都是Eclipse自帶的:

org.eclipse.equinox.http.jetty
org.eclipse.equinox.http.servlet
org.mortbay.jetty
org.apache.commons.logging
javax.servlet
org.eclipse.equinox.http.registry

3. 在例子項目根目錄下創建一個放置web文件的目錄,如“web_files”,在這個目錄下寫一個簡單的index.html文件。

4. 為項目建一個plugin.xml文件,內容如下:


 
  alias="/web"
  base-name="/web_files"/>
 

注意,這時若MANIFEST.MF里提示錯誤,只要在Bundle-SymbolicName這一行后面加上“;singleton:=true”即可解決。

5. 現在可以啟動這個應用程序了。在Eclipse菜單里選擇“Run->Open Run Dialog...”,在左邊的 “OSGi Framework”項下創建一個新的啟動配置項,在右邊先點“Deselect All”清空所有復選框,然后在Workspace下選中自己的osgi項目,再點“Add Required Bundles”按鈕,Eclipse會自動把所依賴的項目選中。最后按“Debug”按鈕啟動,內嵌的jetty和我們的項目會一起被啟動。

 

6. 打開瀏覽器,輸入“http://localhost/web/index.html”應該可以看到index.html里的內容。

以上只驗證了靜態頁面,現在來配置一個servlet看看。

7. 在項目里創建一個繼承自HttpServlet的類,覆蓋doGet()方法,內容是在網頁上打印一些文本。

8. 在項目的plugin.xml里添加下面的內容,這些內容指定了servlet的訪問路徑和實現類:


  alias="/exampleServlet"
  class="net.bjzhanghao.osgi.example.servlet.ExampleServlet"/>

9. 重新啟動項目,在瀏覽器里輸入“http://localhost/exampleServlet”,應該可以看到servlet的輸出。

二、支持JSP頁面

10. 在index.html所在目錄下創建一個簡單的jsp文件index.jsp

11. 打開項目的MANIFEST.MF文件,添加如下項目依賴:

org.eclipse.equinox.jsp.jasper,
org.apache.jasper,
org.eclipse.equinox.jsp.jasper.registry,
javax.servlet.jsp,
org.apache.commons.el,
org.eclipse.equinox.http.helper,
org.eclipse.osgi,
org.eclipse.osgi.services

其中org.eclipse.equinox.http.helper需要從cvs里下載得到(目前是在/cvsroot/eclipse下的 equinox-incubator目錄里,以后可能會直接放到/cvsroot/eclipse下)。

12. 修改Activator,目的是注冊一個處理擴展名為.jsp類型的servlet,感覺這一步以后應該有更簡單的方法,例如通過擴展點。

public class Activator implements BundleActivator {

private ServiceTracker httpServiceTracker;

String jspContext = "/jsps";
String jspFolder = "/web_files";

public void start(BundleContext context) throws Exception {
httpServiceTracker = new HttpServiceTracker(context);
httpServiceTracker.open();
}

public void stop(BundleContext context) throws Exception {
httpServiceTracker.open();
}

private class HttpServiceTracker extends ServiceTracker {

public HttpServiceTracker(BundleContext context) {
super(context, HttpService.class.getName(), null);
}

public Object addingService(ServiceReference reference) {
final HttpService httpService = (HttpService) context
.getService(reference);
try {
HttpContext commonContext = new BundleEntryHttpContext(context
.getBundle(), jspFolder);
httpService.registerResources(jspContext, "/", commonContext);

Servlet adaptedJspServlet = new ContextPathServletAdaptor(
new JspServlet(context.getBundle(), jspFolder),
jspContext);
httpService.registerServlet(jspContext + "/*.jsp",
adaptedJspServlet, null, commonContext);
} catch (Exception e) {
e.printStackTrace();
}
return httpService;
}

public void removedService(ServiceReference reference, Object service) {
final HttpService httpService = (HttpService) service;
httpService.unregister(jspContext);
httpService.unregister(jspContext + "/*.jsp");
super.removedService(reference, service);
}
}
}

13. 打開Debug對話框,選中workspace里的例子osgi項目和org.eclipse.equinox.http.helper項目,再按“Add Required Bundles”按鈕,然后啟動程序。

14. 在瀏覽器里輸入“http://localhost/jsps/index.jsp”,應該可以看到jsp輸出。

您正在閱讀:Equinox OSGi服務器應用程序的配置步驟

【編輯推薦】

  1. Eclipse、Equinox和OSGi
  2. Equinox OSGi系列之一 Equinox入門
  3. 探索Eclipse的OSGi控制臺
責任編輯:張攀 來源: 博客園
相關推薦

2009-06-18 10:03:57

EquinoxOSGi應用服務器

2009-11-18 09:48:38

Windows PHP

2009-06-01 11:28:48

EquinoxOSGi入門

2009-06-25 17:08:14

2017-11-10 08:58:49

Web服務器應用程序

2011-09-06 10:58:10

服務器應用程序虛擬化

2009-10-15 15:12:39

Equinox服務器端Equinox

2010-04-16 13:32:28

Win2008 R2

2009-09-29 14:20:05

OSGiContactDAO

2011-07-22 18:44:45

iPhone HTTPS 服務器

2009-10-22 11:03:20

OSGi Web應用程

2018-03-12 09:13:12

應用程序服務器部署

2013-12-11 09:56:10

存儲加速器

2011-11-16 11:30:08

虛擬化虛擬服務器虛擬服務器備份

2019-05-14 09:39:07

Web服務器Web容器應用程序服務器

2009-10-19 14:14:19

OSGi Web應用

2024-01-03 11:44:26

開發云服務

2010-07-01 14:22:02

配置FTP服務器

2011-07-26 16:43:59

iPhone Web 服務器

2018-11-23 08:54:27

服務器程序監控
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 欧美国产中文 | 精品欧美一区二区中文字幕视频 | 91视频久久| 午夜码电影 | 欧美一区二区三区的 | 97精品一区二区 | 在线观看av网站永久 | 337p日韩| av中文字幕在线播放 | 99精品久久久 | 天天av网 | 亚洲国产精品一区二区三区 | 亚洲一区不卡 | 老司机精品福利视频 | 国产日韩一区二区 | 91最新入口 | 日本小电影在线 | 欧美一区二不卡视频 | 国产91久久精品一区二区 | 欧美激情综合 | 亚洲精品九九 | 国产精品一卡二卡三卡 | 999久久久国产精品 欧美成人h版在线观看 | 欧美13videosex性极品 | 色婷婷综合久久久中字幕精品久久 | 美女露尿口视频 | 亚洲一区在线日韩在线深爱 | 天天操狠狠操 | 一级一片在线观看 | 免费色网址 | 天堂av中文在线 | 亚洲最大福利网 | 91亚洲精品国偷拍自产在线观看 | 99亚洲视频 | 伊人久久在线观看 | 欧美不卡一区二区三区 | 久久久免费在线观看 | 麻豆一区二区三区精品视频 | 欧美日韩高清在线观看 | 色偷偷888欧美精品久久久 | 亚洲男人天堂网 |