Eclipse RCP中的Firefox

马蒂亚斯·布劳恩(Matthias Braun)

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

我尝试使用下面在此处找到的代码加载XULRunner

    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)

如果我file:///在XULRunner的路径之前删除c is not a registered protocol,则会在XULrunner 3.6.25中收到错误

有人知道这个特殊的XPCOM错误是什么意思,以及如何解决它吗?

马蒂亚斯·布劳恩(Matthias Braun)

此答案的基础上,这些步骤使Firefox在Eclipse中为我工作:

  1. 安装Ajax工具框架(http://wiki.eclipse.org/ATF/Installing
  2. 在“运行配置...”(Run Configurations ...)->“插件”(Plug-ins)下,添加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);
    

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章