Q: Can I specify which XULRunner installation gets used?
A: Typically a Mozilla-based Browser uses XULRunner's lookup mechanism
to find a registered XULRunner at runtime, in which case a XULRunner location
does not need to be specified. However if you wish to override this mechanism 
you can set the value of java system property org.eclipse.swt.browser.XULRunnerPath 
to point at an alternate XULRunner's path. This property must be set before 
the first Browser instance is created.

The best opportunity for a user to set this property is by launching 
their application with a -D VM switch (eg.- add to the end of the 
eclipse.ini file: -Dorg.eclipse.swt.browser.XULRunnerPath=...).

An alternate approach that an eclipse application may use is to provide 
a XULRunnerInitializer implementation that sets this property. 
This implementation will be invoked when the first Mozilla-based Browser 
is about to be created. The steps to do this are:

Create a fragment with host plug-in org.eclipse.swt.
In this fragment create class org.eclipse.swt.browser.XULRunnerInitializer.
Implement a static initializer in this class that sets 
the org.eclipse.swt.browser.XULRunnerPath property. 
As an example, the class below will set the property 
to the win32 xulrunner plug-in if it is present.

        package org.eclipse.swt.browser;

        import org.eclipse.core.runtime.*;
        import org.osgi.framework.Bundle;

        public class XULRunnerInitializer {
            static {
                Bundle bundle = Platform.getBundle("org.mozilla.xulrunner.win32.win32.x86"); //$NON-NLS-1$
                if (bundle != null) {
                    URL resourceUrl = bundle.getResource("xulrunner"); //$NON-NLS-1$
                    if (resourceUrl != null) {
                        try {
                            URL fileUrl = FileLocator.toFileURL(resourceUrl);
                            File file = new File(fileUrl.toURI());
                            System.setProperty("org.eclipse.swt.browser.XULRunnerPath",file.getAbsolutePath()); //$NON-NLS-1$
                        } catch (IOException e) {
                            // log the exception
                        } catch (URISyntaxException e) {
                            // log the exception

Updated by Alexey Demakov almost 11 years ago ยท 4 revisions