如何使SWT浏览器控件在Windows上使用Mozilla而不是IE?

时间:2010-01-18 14:44:43

标签: firefox browser swt

我想让SWT在我运行我的应用程序的所有平台上使用Firefox。但SWT当然默认在Windows上使用IE。任何想法如何让SWT在Windows上使用Mozilla。我知道我需要在机器上安装XULRunner。

2 个答案:

答案 0 :(得分:6)

有趣的是你问过 - 我只需要为我们的项目做同样的事情。

  1. 转到ATF网站(http://wiki.eclipse.org/ATF/Installing) - 如何从Zend网站上下载XUL Runner。
  2. 此代码可让您在不注册XULRunner的情况下运行浏览器:
  3. <强>代码:

    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.XULRunnerPath",file.getAbsolutePath()); //$NON-NLS-1$
            } catch (IOException e) {
                // log the exception
            } catch (URISyntaxException e) {
                // log the exception
            }
        }
    }
    

    此处有更多详情:http://www.eclipse.org/swt/faq.php#howusemozilla

    注意:我的代码与常见问题解答(不同的插件ID)略有不同 - 我这样对我有用。

答案 1 :(得分:4)

我刚刚找到答案。

  1. 您需要在您的计算机上注册XULRunner。为此,只需将其解压缩,然后在命令shell xulrunner.exe --register-global中执行此命令。
  2. SWT.MOZILLA样式传递给浏览器构造函数:Browser browser = new Browser(shell, SWT.MOZILLA);