views:

139

answers:

4

As outline in a previous question I asked.

A website can be launched by doing this:

Desktop.getDesktop().browse(new java.net.URI("www.google.com"));

This works fine in Ubuntu(gnome), but it doesn't appear to work in OpenSUSE(KDE flavour). There is a bug lodged with Sun about this.

Any ideas on alternate ways to do this, that will work in both Gnome and KDE.

A: 

strace -f it and see what gets executed. I wonder what java is thinking it's a good police for cross-desktop browser execution.

elcuco
+1  A: 

While waiting for the bug fix from Sun/Oracle, you can find the user's default browser and invoke it yourself using the ProcessBuilder class. You can find the default browser in gnome using the gnonftool-2 utility. I'm not sure how in KDE. Here's an example where I try to find if the user is running Clearlooks on gnome:

private boolean usingClearlooks() {
    try {
        File gconf = new File("/usr/bin/gconftool-2");
        if(gconf.exists() == false) {
            return false;
        }
        ProcessBuilder pb = new ProcessBuilder(gconf.getAbsolutePath(), "-g", "/desktop/gnome/interface/gtk_theme");
        Process psProc = pb.start();
        psProc.waitFor();
        BufferedReader br = new BufferedReader(new InputStreamReader(psProc.getInputStream()));
        boolean clearlooks = false;
        String line = null;
        while((line=br.readLine()) != null) {                                                       
            if ((line.toLowerCase().contains("clearlooks"))) {
                clearlooks = true;
                break;
            }
        }
        return clearlooks;
    }
    catch(Exception e) {
        e.printStackTrace();
        return false;
    }
}
Yuvi Masory
A: 

If you don't mind using an extra library you could try JDIC

vickirk
+1  A: 

As a workaround, you could run the standard command to open files or URLs on any Linux desktop: xdg-open.

http://portland.freedesktop.org/xdg-utils-1.0/xdg-open.html

Danilo Piazzalunga