日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
EquinoxOSGi服務器應用程序的配置步驟

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

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

一、支持靜態(tài)頁面和Servlet

1. 創(chuàng)建一個新的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. 在例子項目根目錄下創(chuàng)建一個放置web文件的目錄,如“web_files”,在這個目錄下寫一個簡單的index.html文件。

4. 為項目建一個plugin.xml文件,內(nèi)容如下:

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

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

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

 

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

以上只驗證了靜態(tài)頁面,現(xiàn)在來配置一個servlet看看。

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

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

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

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

二、支持JSP頁面

10. 在index.html所在目錄下創(chuàng)建一個簡單的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服務器應用程序的配置步驟


新聞名稱:EquinoxOSGi服務器應用程序的配置步驟
網(wǎng)站路徑:http://m.5511xx.com/article/codpsoj.html