java - 在 Eclipse 插件中,如何使用系统浏览器启动 web url?

标签 java eclipse browser

我正在开发 eclipse 插件。它需要启动系统浏览器并打开一个链接。在 Swing/SWT 中,我可以这样做:

java.net.URI uri = new java.net.URI("http://www.google.com");
java.awt.Desktop.getDesktop().browse(uri);

事实上,这段代码在Eclipse 插件中也有效。但我想知道 eclipse 是否有自己的方法来做到这一点?在 eclipse 中使用 AWT 似乎有点奇怪......

最佳答案

java.awt.Desktop.getDesktop().browse(uri) 的等价物是这个 Program.launch("http://www.google.com");

import org.eclipse.swt.program.Program;

public class del 
{
    public static void main(String[] args) 
    {
        Program.launch("http://www.google.com");
    }
}

javadoc 说:

Launches the operating system executable associated with the file or URL (http:// or https://). If the file is an executable then the executable is launched. Note that a Display must already exist to guarantee that this method returns an appropriate result.

关于java - 在 Eclipse 插件中,如何使用系统浏览器启动 web url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4534571/

相关文章:

java - 如何创建一个简单的json结果集?

java - 在 Java 中导入 Scala : weird classes & methods showing

java 添加到ArrayList后如何访问textField

html - 如何停止缓存 html 但继续缓存其他资源

javascript - processing.js 如何检测浏览器的大小?

java - Spring调度线程未访问数据库

java - 如何使用 eclipse kepler 和 apache 7 制作并运行 servlet

eclipse - 您如何在 eclipse/springsource 工具套件中安装 jre?

安卓 Ant : Build release with Debug option

c# - DocumentCompleted 的 WPF 等价物是什么?