Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse: The SWT browser widget could not be created

I have installed eclipse (4.10) on my Linux Machine (KDE Neon 5.15) and everything works quite well except for the JavaDoc. Whenever I view the JavaDoc-hover, I get a plain text representation and at the bottom it says

NOTE: The SWT Browser widget could not be created. This fallback mode doesn't show links and misses other functionality.

Further investigation led me to create a minimal SWT-example using the SWT Browser widget:

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class BrowserTest {
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);

        shell.setLayout(new FillLayout());

        Browser b = new Browser(shell, SWT.NONE);
        b.setUrl("www.google.com");

        shell.open();

        while (!shell.isDisposed()) {
            display.readAndDispatch();
            display.sleep();
        }

        display.dispose();
    }
}

Trying to execute this code failed with the exception

Exception in thread "main" org.eclipse.swt.SWTError: No more handles [Browser style SWT.MOZILLA and Java system property org.eclipse.swt.browser.DefaultType=mozilla are not supported with GTK 3 as XULRunner is not ported for GTK 3 yet]
    at org.eclipse.swt.SWT.error(Unknown Source)
    at org.eclipse.swt.browser.MozillaDelegate.<init>(Unknown Source)
    at org.eclipse.swt.browser.Mozilla.create(Unknown Source)
    at org.eclipse.swt.browser.Browser.<init>(Unknown Source)
    at Main.main(Main.java:31)

which clearly shows that the system is indeed unable to create the browser widget. Although this time the error message is more informative.
I also tried setting the style of the browser widget to SWT.MOZILLA which yielded the same error message (as expected) and using SWT.WEBKIT also threw the same error, though without any explanatory text (so only org.eclipse.swt.SWTError: No more handles).

like image 382
Raven Avatar asked Apr 06 '19 10:04

Raven


2 Answers

From the error message and from some further research it is clear, that the SWT browser widget relies on the XULRunner software to render HTML. As the error message states, this hasn't been ported to GTK3 (yet) and can thus not be used. Per default eclipse does start in GTK3-mode though, so that's the root problem.

An attempt to solve it could be to force eclipse into GTK2-mode (see here) but further investigation of the Eclipse FAQ shows, that from Eclipse 4.8 and onward XULRunner isn't supported at all anymore.

Therefore the option to use the SWT.MOZILLA style for creating the browser seems to be invalid in those versions. Instead one has to focus on getting the SWT.WEBKIT style to work. For that another visit in the FAQ reveals that

WebKitGTK 1.2.0 or newer must be in the library load path.

Therefore I went ahead and searched for the respective library and installed it (libwebkitgtk-3.0-0 in my case).
After having installed that package above SWT-snipped started just fine and after having restarted eclipse, the JavaDoc was back to full functionality.

If this doesn't work for you directly, you might have to set the org.eclipse.swt.browser.DefaultType variable accordingly. According to this question, this can be done by ensuring that -Dorg.eclipse.swt.browser.DefaultType=webkit is in the eclipse.ini file.

like image 93
Raven Avatar answered Nov 13 '22 00:11

Raven


For arch linux I had to install webkit2gtk from the AUR to get it working.

like image 2
JSamir Avatar answered Nov 12 '22 23:11

JSamir