Search code examples
javaeclipseubuntuswtxulrunner

Java XULRunner error in Eclipse / SWT in Ubuntu


What's wrong with XULRunner So, I have next environment:

  • Ubuntu 14.04
  • Installed XULRunner
  • Eclipse 4.5.2

So,

    public class Main {
       public static void main(String[] args) {

            System.setProperty("org.eclipse.swt.browser.DefaultType", "mozilla");
            System.setProperty("org.eclipse.swt.browser.XULRunnerPath", "/opt/xulrunner/xulrunner");

            Display display = new Display();
            final Shell shell = new Shell(display);

            Browser webBrowser = new Browser(shell, SWT.MOZILLA);
            GridData grid = new GridData(GridData.FILL_BOTH);
            webBrowser.setLayoutData(grid);
            String graphUrl = "http://google.com";
            webBrowser.setUrl(graphUrl);
       }
    }

But in Eclipse i see:

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)

Doesn't help:

XULRunner error in Eclipse / SWT

How to install XULRunner for Eclipse

How to make SWT Browser control use Mozilla instead of IE on Windows?


Solution

  • XULRunner is not ported to GTK3 yet, so you have to make it run in GTK2 mode by editing eclipse.ini, which you will find in the eclipse installation dir.

    Check to see if your eclipse.ini contains a line that starts with --launcher, for example

    --launcher.appendVmargs
    

    Put the following two lines before that one:

    --launcher.GTK_version
    2
    

    Yes, they need to be on separate lines.

    If you don't find a line that starts with --launcher., find a line that says just --vm and put those two lines on the lines before it, and if you don't find a --vm line, put it on the line before --vmargs.

    You should then end up with a file that looks like this. Note this is just an example:

    --launcher.GTK_version
    2
    --launcher.appendVmargs
    

    OR

    --launcher.GTK_version
    2
    --vm (or --vmargs)