我正在开发 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/