javaeclipseswtxulrunner

XULRunner error in Eclipse / SWT


I'm trying to run the Enhanced JavaScript Bridge example found here.

I created a new project, and added a reference to SWT via:

Project(right-click)-->Properties-->Libraries-->Add Variable-->Configure Variable-->New

However I cannot get this project to run. The error I get depends on what SWT library I'm referencing:

Could not instantiate Browser: org.eclipse.swt.internal.mozilla.init.XPCOMInit.GREVersionRange_sizeof()I

Could not instantiate Browser: No more handles [Could not detect registered XULRunner to use]

It seems I am having a problem with XULRunner or the Mozilla browser. I tried using different XULRunner versions (10, 18, 24) by running xulrunner.exe --register-global in the console in their respective folders. It didn't help. I don't know what else to do.

My system is:


Solution

  • Ok, so I managed to get XULRunner working in the following way:

    1) Download XULrunner 24.0. You can find the versions I used here:

    2) In my Java code I create a Composite to contain my Browser object.

    In its constructor I set the path to the xulrunner folder I downloaded in step 1, and then instantiate the browser:

    public class MyBrowserComp extends Composite {
    
        private String pathToXulrunner = "C:\\path\\to\\xulrunner";`
    
        private Browser browser;
    
        public MyBrowserComp(..) {
            System.setProperty("org.eclipse.swt.browser.XULRunnerPath", pathToXulrunner);
            browser = new Browser(this, SWT.MOZILLA);
        }
    }