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();
}
}
}
# 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");