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