In the Eclipse Plug-in, how to launch a web url using a system browser?

I am working on developing an eclipse plugin. He needs to start the system browser and open the link. In Swing / SWT, I can do it like this:

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

And in fact, this code also works in the Eclipse plug-in. But I am wondering if eclipse has its own way of doing this? Using AWT in eclipse seems weird ...

+4
source share
1 answer

Equivalent to java.awt.Desktop.getDesktop().browse(uri) is 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"); } } 

The javadoc says:

The operating system starts the executable file associated with the file or URL (http: // or https: //). If the file is executable, then the executable is launched. Note that a display must already exist to ensure that this method returns the appropriate result.

+6
source

Source: https://habr.com/ru/post/1333405/


All Articles