Wiki » History » Version 3
Alexey Demakov, 01/27/2012 04:10 PM
1 | 3 | Alexey Demakov | <pre>Q: Can I specify which XULRunner installation gets used? |
---|---|---|---|
2 | 2 | Alexey Demakov | 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. |
3 | 1 | Alexey Demakov | |
4 | 2 | Alexey Demakov | 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=...). |
5 | 1 | Alexey Demakov | |
6 | 2 | Alexey Demakov | 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: |
7 | 1 | Alexey Demakov | |
8 | 2 | Alexey Demakov | Create a fragment with host plug-in org.eclipse.swt. |
9 | In this fragment create class org.eclipse.swt.browser.XULRunnerInitializer. |
||
10 | 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. |
||
11 | 1 | Alexey Demakov | |
12 | 3 | Alexey Demakov | <code class="java"> |
13 | 1 | Alexey Demakov | package org.eclipse.swt.browser; |
14 | |||
15 | import java.io.*; |
||
16 | import java.net.*; |
||
17 | import org.eclipse.core.runtime.*; |
||
18 | import org.osgi.framework.Bundle; |
||
19 | |||
20 | public class XULRunnerInitializer { |
||
21 | static { |
||
22 | Bundle bundle = Platform.getBundle("org.mozilla.xulrunner.win32.win32.x86"); //$NON-NLS-1$ |
||
23 | if (bundle != null) { |
||
24 | URL resourceUrl = bundle.getResource("xulrunner"); //$NON-NLS-1$ |
||
25 | if (resourceUrl != null) { |
||
26 | try { |
||
27 | URL fileUrl = FileLocator.toFileURL(resourceUrl); |
||
28 | File file = new File(fileUrl.toURI()); |
||
29 | System.setProperty("org.eclipse.swt.browser.XULRunnerPath",file.getAbsolutePath()); //$NON-NLS-1$ |
||
30 | } catch (IOException e) { |
||
31 | // log the exception |
||
32 | } catch (URISyntaxException e) { |
||
33 | // log the exception |
||
34 | } |
||
35 | } |
||
36 | } |
||
37 | } |
||
38 | } |
||
39 | |||
40 | 2 | Alexey Demakov | |
41 | 3 | Alexey Demakov | </code></pre> |