將Eclipse RAP部署到Tomcat中
在上次成功將我的RCP項(xiàng)目遷移到瀏覽器中運(yùn)行后,開(kāi)始研究怎樣將它部署到Tomcat中,說(shuō)實(shí)話,到目前為止,這方面的資料很少,在Eclipse RAP的新聞組上關(guān)于這方面的討論也不是很多。RAP的幫助系統(tǒng)中的介紹文章好像也不是很詳細(xì)(好像有點(diǎn)過(guò)時(shí))
這里我們簡(jiǎn)單介紹一下部署Eclipse RAP 自帶的RAP例子,如果安裝了Eclipse RAP,打開(kāi)幫助界面,找到RAP幫助文檔中的“How to deploy a RAP application to a servlet container?“ 這篇文章,文章中提供了一個(gè)鏈接方式,可以下載一個(gè)psf,這是Eclipse的工程集文件,文件內(nèi)容如下:
- <?xml version= "1.0" encoding= "UTF-8" ?>
- <psf version="2.0" >
- <provider id="org.eclipse.team.cvs.core.cvsnature" >
- <project reference="1.0,:pserver:anonymous@dev.eclipse.org:/cvsroot/rt,org.eclipse.equinox/server-side/bundles/org.eclipse.equinox.http.servletbridge,org.eclipse.equinox.http.servletbridge" />
- <project reference="1.0,:pserver:anonymous@dev.eclipse.org:/cvsroot/rt,org.eclipse.equinox/server-side/bundles/org.eclipse.equinox.servletbridge,org.eclipse.equinox.servletbridge" />
- <project reference="1.0,:pserver:anonymous@dev.eclipse.org:/cvsroot/rt,org.eclipse.rap/releng/org.eclipse.rap.demo.feature,org.eclipse.rap.demo.feature" />
- </provider>
- </psf>
你也可以將內(nèi)容復(fù)制到文本文件然后改成 yourpsffile.psf 文件,將它作為Eclipse的工程集導(dǎo)入到Eclipse中,Eclipse就會(huì)自動(dòng)從Eclipse的CVS網(wǎng)站上下載對(duì)應(yīng)的插件,總共有三個(gè)插件被下載下來(lái):
org.eclipse.equinox.http.servletbridge
org.eclipse.equinox.servletbridge
org.eclipse.rap.demo.feature
Java代碼
1. 打開(kāi)org.eclipse.rap.demo.feature工程的script文件夾下的webappBuilder.xml文件,修改屬性名為”servletbridge.dir“的屬性值(好像在 18 行),將值修改為你的”org.eclipse.equinox.servletbridge“工程的路徑,推薦使用絕對(duì)路徑,比如:
- <property name= "servletbridge.dir"
- value="D:/DeveloperWorks/Eclipse-3.5-RAP-SRC/org.eclipse.equinox.servletbridge" />
然后直接使用Ant運(yùn)行編譯,運(yùn)行后會(huì)在插件的build文件夾下面生成可部署的文件。
打開(kāi)生成的web.xml 文件,將已經(jīng)被注釋的下面內(nèi)容
- <!--
- <init-param>
- <param-name>commandline</param-name>
- <param-value>-console</param-value>
- </init-param>
- -->
中的參數(shù)值由false改成true,這樣可以啟動(dòng)對(duì)OSGI框架的控制,方便調(diào)試。
運(yùn)行工程下面的ConfigIniCreator.java,(應(yīng)該在39行)將指定plugins目錄的路徑修改為你本機(jī)的絕對(duì)路徑,比如我的工程的路徑是:
- File file = new File( "D:\\DeveloperWorks\\Eclipse-3.4-RAP\\org.eclipse.rap.demo.feature\\build\\demo\\WEB-INF\\eclipse\\plugins");
運(yùn)行后將打印的結(jié)果替換\org.eclipse.rap.demo.feature\build\demo\WEB-INF\eclipse\configuration目錄的config.ini文件內(nèi)容。
接 接著將org.eclipse.rap.demo.feature工程下面的build文件夾下的demo文件夾下面的內(nèi)容復(fù)制到Tomcat的webapps目錄下,啟動(dòng)Tomcat,啟動(dòng)后可在控制臺(tái)輸入 ”ss" 查看OSGI框架下已經(jīng)被加載的插件:
可以看到我們部署的org.eclipse.rap.demo文件已經(jīng)處于激活狀態(tài)了。
打開(kāi)瀏覽器,輸入 http://localhost:8080/demo/rap 就可以進(jìn)行訪問(wèn)了。
原文鏈接:http://marssuburbs.iteye.com/blog/1322383
【編輯推薦】