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

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

新聞中心

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

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

編輯推薦:OSGi入門與實(shí)踐全攻略

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

1. 創(chuàng)建一個(gè)新的plugin項(xiàng)目, net.bjzhanghao.osgi.test,在向?qū)?**步里選中“This plug-in is target,在下一步的“Plug-in Options”里選中“Generate an activator”。

 

2. 在例子項(xiàng)目的MANIFEST.MF里添加如下依賴項(xiàng)目,這些項(xiàng)目都是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. 在例子項(xiàng)目根目錄下創(chuàng)建一個(gè)放置web文件的目錄,如“web_files”,在這個(gè)目錄下寫一個(gè)簡單的index.html文件。

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

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

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

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

 

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

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

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

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

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

9. 重新啟動(dòng)項(xiàng)目,在瀏覽器里輸入“http://localhost/exampleServlet”,應(yīng)該可以看到servlet的輸出。

二、支持JSP頁面

10. 在index.html所在目錄下創(chuàng)建一個(gè)簡單的jsp文件index.jsp

11. 打開項(xiàng)目的MANIFEST.MF文件,添加如下項(xiàng)目依賴:

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目錄里,以后可能會(huì)直接放到/cvsroot/eclipse下)。

12. 修改Activator,目的是注冊一個(gè)處理擴(kuò)展名為.jsp類型的servlet,感覺這一步以后應(yīng)該有更簡單的方法,例如通過擴(kuò)展點(diǎn)。

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項(xiàng)目和org.eclipse.equinox.http.helper項(xiàng)目,再按“Add Required Bundles”按鈕,然后啟動(dòng)程序。

14. 在瀏覽器里輸入“http://localhost/jsps/index.jsp”,應(yīng)該可以看到j(luò)sp輸出。

您正在閱讀: Equinox OSGi服務(wù)器應(yīng)用程序的配置步驟


文章題目:EquinoxOSGi服務(wù)器應(yīng)用程序的配置步驟
本文鏈接:http://www.5511xx.com/article/codpsoj.html