Reputation: 7178
I am trying to use Desktop.browse() to invoke a URL, this works fine on Windows machines or on Linux machines with a default browser configured. However, it throws an IOException exception when no default browser is found on Linux. What are some of the ways to work around this? I suppose I can attempt to launch Firefox and assume its there but I do not want to make that assumption.
Upvotes: 2
Views: 2062
Reputation: 284927
It looks like Desktop.browse() ultimately calls XDesktopPeer.browse() on *ix. That method is implemented by calling gnome_url_show. That probably works fine in some cases, but xdg-open is the cross-platform solution, as others have noted.
Arguably, this is a bug in Sun Java. Bug 6490730, "Desktop throws IOException instead of showing URL or sending mail", (reported November 2006) seems relevant
Upvotes: 2
Reputation: 116382
try xdg-open or just try with konqueror (default on KDE, but not supported by Desktop API) and firefox.
Try also kmclient exec url.
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
// blah blah
} else {
// try to launch xdg-open
// or try launching other browsers?
}
Upvotes: 3
Reputation: 9666
Try to execute xdg-open http://the/url
first if you're going to implement one of the "cycle through a bunch of browsers". That should open the default browser if for some reason Java can't find it. (It does seem likely that this is what Java does anyway.)
Upvotes: 1
Reputation: 882181
You can try various browsers in some order -- firefox, opera, etc, etc; also keep an editable configuration file which lets the user set a browser, remember there the one you found, etc.
Upvotes: 2
Reputation: 13984
You can allow the user to enter the command they want to launch their browser, and then save that command so it will use that command everytime.
Upvotes: 9
Reputation: 26149
I don't think there's much you could do beyond:
Additionally, there is a whole section of the SWT FAQ dedicated to discovering the appropriate version of firefox to use on a particular system (keep reading the questions starting with the one linked above.)
Upvotes: 7