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