Monday, June 25, 2007

Troubles with java.awt.Desktop browse() method

New Desktop features were added in Java 6. One of those features is browse(URI uri) method, which launches the user-default browser to show a specified URI.
So, it is quite easy to show some web-page to user: check if desktop is supported, then check if BROWSE action is supported and call browse() method. Here is some code chunk:

try {
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(new URI(""));
} catch (Exception e) {

Everything seams to be fine. But when you run it on Fedora 6 on KDE it ends up with Failed to show URI:
at sun.awt.X11.XDesktopPeer.launch(
at sun.awt.X11.XDesktopPeer.browse(
at java.awt.Desktop.browse(
at Main.main(

So, you go to Sun's bug database and start searching what is going on. And here it is: bug 6486393 (Need a KDE support in java.awt.Desktop class). So, it turns out that Desktop API was developed to support Windows and Gnome only. Upps.
OK, you are switching to Gnome on the same Fedora 6, run the example again and... you have the same exception. It does not work.
Two question are arising to Sun's engineers:
  1. Why KDE is simply ignored?
  2. Is it so difficult to add support even for Gnome that works?


Anonymous said...


I had the same problem to run this code line: Desktop.getDesktop().browse(new URI("")); in ubuntu 8.04 (gnome)!

The solution for my system is change in:
Desktop.getDesktop().browse(new URI(""));

or for a local file:
Desktop.getDesktop().browse(new URI("file:///home/.../index.html"));

sincerly yours

Anonymous said...

Who knows it.

Anonymous said...

I have passed something?

Anonymous said...

I have problems when uploading pictures on facebook