//////////////////////////////////////// /////////////////
// Bare bones browser launch //
// Version 1.5 //
// December 10,200 5 //
// Supports: Mac OS X, GNU/Linux, UNIX, Windows XP //
// Example usage ://
// String url = "http://www.centerkey.com /";//
// Barebonesbrowserlaunch. Openurl (URL );//
// Public domain software -- free to use as you like //
//////////////////////////////////////// /////////////////
Import java. Lang. Reflect. method;
Import javax. Swing. joptionpane;
Public class barebonesbrowserlaunch {
Private Static final string errmsg = "error attempting to launch Web Browser ";
Public static void Openurl (string URL ){
String osname = system. getproperty ("OS. Name ");
Try {
If (osname. startswith ("Mac OS ")){
Class filemgr = Class. forname ("com. Apple. EIO. filemanager ");
Method Openurl = filemgr. getdeclaredmethod ("Openurl ",
New Class [] {string. Class });
Openurl. Invoke (null, new object [] {URL });
}
Else if (osname. startswith ("Windows "))
Runtime.getruntime(cmd.exe C ("rundll32 URL. dll, fileprotocolhandler" + URL );
Else {// assume Unix or Linux
String [] browsers = {
"Firefox", "Opera", "Konqueror", "Epiphany", "Mozilla", "Netscape "};
String browser = NULL;
For (int count = 0; count <browsers. Length & browser = NULL; count ++)
If (runtime.getruntime(cmd.exe C (
New String [] {"which", browsers [count]}). waitfor () = 0)
Browser = browsers [count];
If (Browser = NULL)
Throw new exception ("cocould not find Web Browser ");
Else
Runtime.getruntime(cmd.exe C (New String [] {browser, URL });
}
}
Catch (exception e ){
Joptionpane. showmessagedialog (null, errmsg + ":" + E. getlocalizedmessage ());
}
}
}
From: http://www.java2s.com/Code/Java/Development-Class/LaunchBrowserinMacLinuxUnix.htm