java - Eclipse RCP 中的 Firefox

标签 java firefox swt eclipse-rcp xulrunner

我正在尝试使用 Firefox 作为在 Eclipse RCP 插件内运行的 SWT 浏览器。

我尝试使用以下代码加载 XULRunner,我发现 here :

    Bundle bundle = Platform.getBundle(PLUGIN_NAME); //$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:///" + file.getAbsolutePath()); //$NON-NLS-1$
                System.setProperty("org.eclipse.swt.browser.DefaultType",
                        "mozilla");

            } catch (IOException e) {
                e.printStackTrace();
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        }
    }
    Browser webBrowser = new Browser(parent, SWT.MOZILLA);

我使用的是 Windows 7 x86 和 Eclipse Indigo。我尝试过XULrunner 3.6.25和10。我使用的Firefox版本是10和22。

无论什么版本,它都会崩溃并给出以下堆栈跟踪:

org.eclipse.swt.SWTError: XPCOM error -2147467259
at org.eclipse.swt.browser.Mozilla.error(Mozilla.java:2502)
at org.eclipse.swt.browser.Mozilla.initXULRunner(Mozilla.java:2464)
at org.eclipse.swt.browser.Mozilla.create(Mozilla.java:672)
at org.eclipse.swt.browser.Browser.<init>(Browser.java:99)

如果我删除 XULRunner 路径之前的 file:///,我会在 XULrunner 3.6.25 中收到错误 c 不是注册协议(protocol)

有人知道这个特定的 XPCOM 错误意味着什么以及如何修复它吗?

最佳答案

构建于 this answer ,这些是让 Firefox 在 Eclipse 中为我工作的步骤:

  1. 安装 Ajax 工具框架 ( http://wiki.eclipse.org/ATF/Installing )
  2. 在“运行配置...”->“插件”下添加 org.mozilla.xulrunnerorg.mozilla.xulrunner.win32.win32.x86
  3. 使用以下代码在 swt.browser 中启动 Firefox:

    Bundle bundle = Platform.getBundle("org.mozilla.xulrunner"); //$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.DefaultType",
                        "mozilla");
                System.setProperty(
                        "org.eclipse.swt.browser.XULRunnerPath", file.getAbsolutePath()); //$NON-NLS-1$
    
            } catch (IOException e) {
                e.printStackTrace();
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        }
    } else {
        System.err.println("Could not find XULrunner bundle");
    }
    Browser webBrowser = new Browser(parent, SWT.MOZILLA);
    GridData grid = new GridData(GridData.FILL_BOTH);
    webBrowser.setLayoutData(grid);
    // Prepending "file://" prevents the "<driveletter> is not a registered protocol" error
    String graphUrl = "file://C:/Users/you/yourGraph.html"
    webBrowser.setUrl(graphUrl);
    

关于java - Eclipse RCP 中的 Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17653843/

相关文章:

java - 如何将在 SWT OleClientSite 中打开的文档保存在 eclipse EditorPart 中?

java - SWT 按钮下拉控件

java - 将组合框超出的内容包裹在可用空间中?

java - 使方法只能被模板类中的某些对象访问

java - 如何通过对话框类中的按钮actionPerformed调用我的面板类中的方法,以获取面板类中的实例?

java - 修改之前设置的JEditorPane的CSS样式

c# - 运行 selenium 单元测试时 Firefox 崩溃

firefox - Flash Builder 4.7 无法在 OS X 10.8.4 中启动 Firefox v21.0

java - 为什么在 Apache Tomcat 服务器上运行时无法访问 .properties 文件?

Python Selenium在ubuntu中设置firefox配置文件的路径