Launch browser from java program

Does anyone know how launch your main browser from within a java program. So i have a program and when i run it a panel appears with a menu. this menu has File edit view etc on it within view there is a report button. when i click report i want my browser to appear.

Message was edited by:

djSpeef

[317 byte] By [djSpeefa] at [2007-11-27 6:03:09]
# 1

1. Download Sourceforge's "BrowserLauncher2" class library from here:

http://sourceforge.net/project/showfiles.php?group_id=127980&package_id=142907&release_id=482973

2. Add the file BrowserLauncher2(-all)-10.jar to your CLASSPATH.

3. Create an instance of the edu.stanford.ejalbert.BrowserLauncher class and invoke one of its openURLinBrowser() methods specifying the URL you want to open.

Example

The BrowserLauncher2 class takes an URL as a command line argument and opens it in the default browser.import edu.stanford.ejalbert.BrowserLauncher;

class BrowserLauncher2 {

public static void main(String[] args) {

try {

BrowserLauncher launcher = new BrowserLauncher();

launcher.openURLinBrowser(args[0]);

}

catch (Exception e) {

e.printStackTrace();

}

}

}

prgguya at 2007-7-12 16:45:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Thanks for that. It works great just one question it only works with url. If i want to open an xml file stored in a database how would i go about that.
djSpeefa at 2007-7-12 16:45:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

It seems certain from the BrowserLauncher2 API that you must first convert it to an URL. Anyway, if you want to display any content in a browser, you can only do this by referring to its URL, but this is not a Java-related problem. If you can save your XML document to a file, you can open it like this:launcher.openURLinBrowser("file:///C:/XML/FOO.XML");

prgguya at 2007-7-12 16:45:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
the new java jdk has a built in Desktop class based on the JDIC library which can open the browser and other stuff like system tray icons etc
grilleda at 2007-7-12 16:45:33 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...