4

I am working on an eclipse plugin development. It needs to launch system broswer and open a 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 Eclipse plug-in. But I am wondering if eclipse has its own way to do this? Using AWT in eclipse seems some kind of weird...

DeepNightTwo
  • 4,809
  • 8
  • 46
  • 60
  • Does using Color(s), Font(s), Dimension(s), Image(s) etc. with SWT seem weird? Those are all AWT. I would put it down to some unfortunate choices by Sun and get on with your life/development. – Andrew Thompson Dec 26 '10 at 17:18
  • In SWT, there are org.eclipse.swt.graphics.Color, org.eclipse.swt.graphics.Font and org.eclipse.swt.graphics.Image. I've no specific reasons but I think it is not a good idea to mix up two different UI system. – DeepNightTwo Dec 27 '10 at 05:52

1 Answers1

6

Equivalent of java.awt.Desktop.getDesktop().browse(uri) is this 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:

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.

Favonius
  • 13,959
  • 3
  • 55
  • 95