和Swing應(yīng)用的直接跨平臺(tái)不同,SWT/RCP應(yīng)用要想同時(shí)支持不同平臺(tái),需要做些特殊的配置,不過(guò)并不復(fù)雜,記錄在此,希望能幫到有需要的朋友。目前win32、32位Linux、64位Linux和Mac OS X基本上就覆蓋了所有主流的桌面操作系統(tǒng),本文將以同時(shí)支持這四種OS為例來(lái)進(jìn)行講解。
首先是下載對(duì)應(yīng)版本的RCP框架在不同操作系統(tǒng)的插件,將它們放在同一個(gè)plugins目錄,比如你可以用win32為基礎(chǔ),然后添加針對(duì)其他平臺(tái)的如下插件:
org.eclipse.core.filesystem
org.eclipse.core.filesystem.win32.x86
org.eclipse.core.filesystem.linux.x86
org.eclipse.core.filesystem.linux.x86_64
org.eclipse.core.filesystem.macosx
org.eclipse.core.net
org.eclipse.core.net.win32.x86
org.eclipse.core.net.linux.x86
org.eclipse.core.resources
org.eclipse.core.resources.win32.x86
org.eclipse.equinox.launcher
org.eclipse.equinox.launcher.win32.win32.x86
org.eclipse.equinox.launcher.gtk.linux.x86
org.eclipse.equinox.launcher.gtk.linux.x86_64
org.eclipse.equinox.launcher.carbon.macosx
org.eclipse.equinox.security
org.eclipse.equinox.security.win32.x86
org.eclipse.equinox.security.macosx
org.eclipse.swt
org.eclipse.swt.win32.win32.x86
org.eclipse.swt.gtk.linux.x86
org.eclipse.swt.gtk.linux.x86_64
org.eclipse.swt.carbon.macosx
接下來(lái)將不同平臺(tái)下的eclipse可執(zhí)行文件(Windows下面是eclipe.exe,Linux下是eclipse,Mac OS X下面是Eclipse.app)放到不同的子目錄下,當(dāng)然,如果你的RCP應(yīng)用有別的名稱,也可以重命名eclipse可執(zhí)行文件,按照不同平臺(tái)的規(guī)范更換圖標(biāo),然后修改.ini文件讓它的-startup和-startup.libraray參數(shù)指向相對(duì)路徑中正確版本的插件即可。
最后分享一下我們軟件部署的機(jī)制: 按照前面介紹的方式打包的應(yīng)用程序,交到用戶手里并不是很友好,因?yàn)樾枰?她自己再做一次判斷,當(dāng)前的操作系統(tǒng)是什么,然后打開不同的目錄去點(diǎn)擊不同的可執(zhí)行文件。我們的做法是單獨(dú)提供一個(gè)Swing程序,在客戶端自動(dòng)判斷OS,然后自動(dòng)調(diào)用不同版本的可執(zhí)行文件,同時(shí),這個(gè)Swing程序被做成Java Web Start,把整個(gè)RCP客戶端的下載和同步也處理掉,這樣,對(duì)用戶而言,整個(gè)過(guò)程就透明了,只需要一個(gè)JNLP,剩下的工作完全自動(dòng)化。