Project

General

Profile

Wiki » History » Version 4

Alexey Demakov, 01/27/2012 04:11 PM

1 3 Alexey Demakov
<pre>Q: Can I specify which XULRunner installation gets used?
2 4 Alexey Demakov
A: Typically a Mozilla-based Browser uses XULRunner''s lookup mechanism
3
to find a registered XULRunner at runtime, in which case a XULRunner location
4
does not need to be specified. However if you wish to override this mechanism 
5
you can set the value of java system property org.eclipse.swt.browser.XULRunnerPath 
6
to point at an alternate XULRunner''s path. This property must be set before 
7
the first Browser instance is created.
8 1 Alexey Demakov
9 4 Alexey Demakov
The best opportunity for a user to set this property is by launching 
10
their application with a -D VM switch (eg.- add to the end of the 
11
eclipse.ini file: -Dorg.eclipse.swt.browser.XULRunnerPath=...).
12 1 Alexey Demakov
13 4 Alexey Demakov
An alternate approach that an eclipse application may use is to provide 
14
a XULRunnerInitializer implementation that sets this property. 
15
This implementation will be invoked when the first Mozilla-based Browser 
16
is about to be created. The steps to do this are:
17 1 Alexey Demakov
18
Create a fragment with host plug-in org.eclipse.swt.
19
In this fragment create class org.eclipse.swt.browser.XULRunnerInitializer.
20 4 Alexey Demakov
Implement a static initializer in this class that sets 
21
the org.eclipse.swt.browser.XULRunnerPath property. 
22
As an example, the class below will set the property 
23
to the win32 xulrunner plug-in if it is present.
24
</pre>
25
<pre>
26 3 Alexey Demakov
<code class="java">
27 1 Alexey Demakov
        package org.eclipse.swt.browser;
28
29
        import java.io.*;
30
        import java.net.*;
31
        import org.eclipse.core.runtime.*;
32
        import org.osgi.framework.Bundle;
33
34
        public class XULRunnerInitializer {
35
            static {
36
                Bundle bundle = Platform.getBundle("org.mozilla.xulrunner.win32.win32.x86"); //$NON-NLS-1$
37
                if (bundle != null) {
38
                    URL resourceUrl = bundle.getResource("xulrunner"); //$NON-NLS-1$
39
                    if (resourceUrl != null) {
40
                        try {
41
                            URL fileUrl = FileLocator.toFileURL(resourceUrl);
42
                            File file = new File(fileUrl.toURI());
43
                            System.setProperty("org.eclipse.swt.browser.XULRunnerPath",file.getAbsolutePath()); //$NON-NLS-1$
44
                        } catch (IOException e) {
45
                            // log the exception
46
                        } catch (URISyntaxException e) {
47
                            // log the exception
48
                        }
49
                    }
50
                }
51
            }
52
        }
53
              
54 2 Alexey Demakov
55 3 Alexey Demakov
</code></pre>