對(duì)于 Eclipse 3.1.x 而言,并沒(méi)有書中提到的那個(gè)“org.eclipse.swt.win32_3.0.1”目錄,自然也不會(huì)有目錄下的 swt.jar 和 swt-win32-3063.dll,這個(gè)目錄在 Eclipse 3.1.x 中被 org.eclipse.swt.win32.win32.x86_3.1.x.jar 文件替代,而原生庫(kù)文件也被壓縮到這個(gè) jar 文件中,用 WinRAR 解壓即可得到。
在安裝了 SWT Designer 后通過(guò)其建立項(xiàng)目時(shí),會(huì)自動(dòng)導(dǎo)入所有必須的 jar 文件到項(xiàng)目中,無(wú)需手動(dòng)導(dǎo)入,但如果之前解壓了 org.eclipse.swt.win32.win32.x86_3.1.x.jar 文件,請(qǐng)將解壓目錄刪除之后再建立項(xiàng)目,否則會(huì)導(dǎo)入出錯(cuò)。這個(gè)錯(cuò)誤是因?yàn)閷?dǎo)入了解壓得到的 “org.eclipse.swt.win32.win32.x86_3.1.x”目錄,可以手動(dòng)修改為導(dǎo)入整個(gè) jar 文件就 ok 了。
接下來(lái)是原生庫(kù)的導(dǎo)入,我發(fā)現(xiàn)用書上的方法導(dǎo)入原生庫(kù)到項(xiàng)目中(實(shí)際就是將 swt-win32-xxxx.dll 文件復(fù)制到項(xiàng)目根目錄),會(huì)出現(xiàn)問(wèn)題。后來(lái)翻查《SWT/JFace in Action》得知,有多種方法導(dǎo)入原生庫(kù),但作者發(fā)現(xiàn)的方法是將 swt-win32-xxxx.dll 文件直接復(fù)制到“$Java\jre\bin”目錄下,這樣才不會(huì)引起諸多問(wèn)題。
總結(jié)解決步驟:
①安裝 Eclipse 3.1.x 和 SWT Designer,解壓 org.eclipse.swt.win32.win32.x86_3.1.x.jar 文件。
②復(fù)制 swt-win32-xxxx.dll 到“$Java\jre\bin”目錄下。
③刪除解壓 org.eclipse.swt.win32.win32.x86_3.1.x.jar 得到的文件夾。
④新建 SWT/JFace Java Project,然后就可以直接新建 SWT 類文件了,無(wú)需再導(dǎo)入原生包。
PS:推薦參考《SWT/JFace in Action》配合《Eclipse 入門和精通》進(jìn)行學(xué)習(xí)。在《SWT/JFace in Action》附錄“Creating projects with SWT/JFace”中的 316 頁(yè)可以找到關(guān)于導(dǎo)入原生圖形庫(kù)的講述:
Once you’ve found the graphics library, you need to make sure the application launcher can use it. The documentation lists a number of ways to do this, but we’ve found that adding a copy to the $JAVA/jre/bin directory works best.
Other methods, which can be less reliable, include the following:
Option 1: Copy and paste these files directly in the WidgetWindow project.
Option 2: Include the native library in any directory pointed to by the java.library.path variable. This variable, among others, can be seen by clicking Help->About Eclipse Platform->Configuration Details.
Option 3: Go to Control Panel->System->Advanced->Environmental Variables and update the PATH variable with the directory containing the library file.
在安裝了 SWT Designer 后通過(guò)其建立項(xiàng)目時(shí),會(huì)自動(dòng)導(dǎo)入所有必須的 jar 文件到項(xiàng)目中,無(wú)需手動(dòng)導(dǎo)入,但如果之前解壓了 org.eclipse.swt.win32.win32.x86_3.1.x.jar 文件,請(qǐng)將解壓目錄刪除之后再建立項(xiàng)目,否則會(huì)導(dǎo)入出錯(cuò)。這個(gè)錯(cuò)誤是因?yàn)閷?dǎo)入了解壓得到的 “org.eclipse.swt.win32.win32.x86_3.1.x”目錄,可以手動(dòng)修改為導(dǎo)入整個(gè) jar 文件就 ok 了。
接下來(lái)是原生庫(kù)的導(dǎo)入,我發(fā)現(xiàn)用書上的方法導(dǎo)入原生庫(kù)到項(xiàng)目中(實(shí)際就是將 swt-win32-xxxx.dll 文件復(fù)制到項(xiàng)目根目錄),會(huì)出現(xiàn)問(wèn)題。后來(lái)翻查《SWT/JFace in Action》得知,有多種方法導(dǎo)入原生庫(kù),但作者發(fā)現(xiàn)的方法是將 swt-win32-xxxx.dll 文件直接復(fù)制到“$Java\jre\bin”目錄下,這樣才不會(huì)引起諸多問(wèn)題。
總結(jié)解決步驟:
①安裝 Eclipse 3.1.x 和 SWT Designer,解壓 org.eclipse.swt.win32.win32.x86_3.1.x.jar 文件。
②復(fù)制 swt-win32-xxxx.dll 到“$Java\jre\bin”目錄下。
③刪除解壓 org.eclipse.swt.win32.win32.x86_3.1.x.jar 得到的文件夾。
④新建 SWT/JFace Java Project,然后就可以直接新建 SWT 類文件了,無(wú)需再導(dǎo)入原生包。
PS:推薦參考《SWT/JFace in Action》配合《Eclipse 入門和精通》進(jìn)行學(xué)習(xí)。在《SWT/JFace in Action》附錄“Creating projects with SWT/JFace”中的 316 頁(yè)可以找到關(guān)于導(dǎo)入原生圖形庫(kù)的講述:
Once you’ve found the graphics library, you need to make sure the application launcher can use it. The documentation lists a number of ways to do this, but we’ve found that adding a copy to the $JAVA/jre/bin directory works best.
Other methods, which can be less reliable, include the following:
Option 1: Copy and paste these files directly in the WidgetWindow project.
Option 2: Include the native library in any directory pointed to by the java.library.path variable. This variable, among others, can be seen by clicking Help->About Eclipse Platform->Configuration Details.
Option 3: Go to Control Panel->System->Advanced->Environmental Variables and update the PATH variable with the directory containing the library file.

