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

Bah*_*aid 5 browser firefox swt

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

Eug*_*ene 6

有趣的是你问过 - 我只需要我们的项目一样.

  1. 转到ATF网站(http://wiki.eclipse.org/ATF/Installing) - 有如何从Zend网站下载XUL Runner.
  2. 此代码将允许您在不注册XULRunner的情况下运行浏览器:

码:

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
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

更多细节:http://www.eclipse.org/swt/faq.php#howusemozilla

注意:我的代码与FAQ(不同的插件ID)略有不同 - 我这样对我有用.


Bah*_*aid 5

我刚刚找到了答案。

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

  • 当我运行“xulrunner.exe --register-global”时,它告诉我“错误:无法解析 application.ini”。 (2认同)