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.

+1


a source to share


6 answers


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?
} 

      

+3


a source


You can allow the user to enter the command they want to launch their browser, and then save that command so that it always uses that command.



+9


a source


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.)

+7


a source


You can try different browsers in some order - firefox, opera, etc. etc.; also save an editable config file that allows the user to install the browser, remember that the one you found, etc.

+2


a source


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

+2


a source


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.)

+1


a source







All Articles