国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

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

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

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

1. 創(chuàng)建一個新的plugin項目,net.bjzhanghao.osgi.test,在向?qū)У谝徊嚼镞x中“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)容如下:

<plugin>
  
<extension point="org.eclipse.equinox.http.registry.resources">
    
<resource
      
alias="/web"
      base-name
="/web_files"/>
  
</extension>
</plugin>

注意,這時若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)類:

<extension point="org.eclipse.equinox.http.registry.servlets">
    
<servlet
      
alias="/exampleServlet"
      class
="net.bjzhanghao.osgi.example.servlet.ExampleServlet"/>
</extension>

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輸出。

例子項目下載(鏈接)。

參考鏈接:

本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
使用 Equinox 框架進行 OSGi 環(huán)境下的 Web 開發(fā)
部署并運行你的OSGi Web應用程序
OSGi應用發(fā)布到tomcat
Eclipse 、 Equinox 和 OSGi
初探Java企業(yè)級開源框架OSGi
Eclipse啟動過程(源碼級剖析)
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服