1. 程式人生 > >swt學習之WEBKIT的Safari問題

swt學習之WEBKIT的Safari問題

最近做一個專案,需要用到swt,之前都是swing或者awt,根本不瞭解swt。

網上關於swt的資料很少,有人甚至收swt已經日薄西山了。

這是百度的解釋:

這是維基百科的解釋:

這是討論swt的部落格:

好在基礎比較好,所以看了一下基本就略懂了。

但是到了真正做專案,遇到問題才發現,有些時候,捷徑反而是一條艱難的路。

專案執行在別人的機器上好好的,到我這就不行了。執行測試報錯如下:

org.eclipse.swt.SWTError: No more handles [Safari must be installed to use a SWT.WEBKIT-style Browser]

然後就以為要安裝Safari瀏覽器,結果。。。。安了也不好使。

百度搜了一下,在 the swt faq裡有類似的問題點選開啟連結

裡面的回答是這樣的:

A: To specify that a WebKit renderer be used by a Browser instance, create it with style SWT.WEBKIT (@since 3.7). The runtime requirements for using WebKit-based Browsers are listed below. Note that failure to meet these runtime requirements will cause the Browser instantiation to fail.
  • Windows:
    • 32-bit SWT
    • Safari must be installed
    • For OSs older than XP+SP1, the path to the Apple Application Support installation must be prepended to Windows' "Path" environment variable before running eclipse. This installation will be in a location like "C:\Program Files\Safari\Apple Application Support" or "C:\Program Files\Common Files\Apple\Apple Application Support
      ". If more than one of these directories are found then choose the one with "Safari" in its directory ancestry.
  • Linux: WebKitGTK 1.2.0 or newer must be in the library load path. Examples of Linux distros that meet this requirement by default include Red Hat Enterprise Linux 6 and Ubuntu 10.04.
  • OS X: No additional runtime requirements, the default renderer is WebKit-based.

It is important to note that conflicts have been reported between the dependent libraries of WebKit and Mozilla. As a result it is advised that Browser instances with these respective types not be mixed in an application. If a Browser with one of these types must be used in an application then java property org.eclipse.swt.browser.DefaultType should also be set to this type to ensure that SWT.NONE-style Browsers do not cause the libraries from the other native browser renderer to be loaded (see How do I specify the default type of native renderer that is used by the Browser?).

看完之後才明白,原來是程式裡面有一個地方寫的出了問題。

原來寫法如下:

Browser ie_ad = new Browser(shell, 65536);

後來,想高大上,寫成了Browser ie_ad = new Browser(shell, SWT.WEBKIT);

這句導致程式需要Safari的支援。。。。

後來,改了一下,是這樣:

Browser ie_ad = new Browser(shell, SWT.NONE);

執行程式,問題完美解決。得意