Linux default browser workaround?
I'm trying to use Desktop .browse () to call a url, this works fine on windows machines or Linux machines with default browser setting. However, it will throw an IOException if there is no default browser installed on Linux. What are some of the ways to get around this? I suppose I can try to start Firefox and assume it's there, but I don't want to make that assumption.
a source to share
try xdg-open or just try with konqueror (default in KDE but not supported by Desktop API) and firefox.
Try also the cmclient exec url.
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
// blah blah
} else {
// try to launch xdg-open
// or try launching other browsers?
}
a source to share
I don't think you could do much further:
- Check common locations for common browsers (firefox, mozilla, etc.).
- Iterate the PATH environment variable that looks for common browser executables.
- Give the user a configuration.
Also, there is an entire SWT FAQ section dedicated to finding the appropriate version of firefox to use on a specific system (keep reading the questions starting with the one linked above.)
a source to share
It looks like Desktop.browse () ends up calling XDesktopPeer.browse () on * ix. This method is implemented by calling gnome_url_show . This probably works fine in some cases, but xdg-open is a cross platform solution as others have noted.
This may be a bug in Sun Java. Bug 6490730 , "Desktop throws IOException instead of showing URL or sending mail" (reported November 2006) seems relevant
a source to share
Try this first xdg-open http://the/url
if you are going to implement one of the "loops through a bunch of browsers". This should open the default browser if for some reason Java cannot find it. (It looks like this is what Java does.)
a source to share