Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Desktop browse does not work in java for Ubuntu [duplicate]

desktop = Desktop.getDesktop().browse(uri);

The above code does not work in the Ubuntu OS. If I execute this code, then my application gets struck and hangs for a while and during that time I cannot stop the running application in java console. The only way am able to close that application is by FORCE QUIT.

like image 491
GowthamIyer Avatar asked Feb 21 '14 11:02

GowthamIyer


2 Answers

There are several threads on this issue. I have the same hangs on Ubuntu 16.04. I have posted here the workaround that I'm using: Desktop.getDesktop().browse Hangs

like image 114
OlivierGrenoble Avatar answered Nov 10 '22 16:11

OlivierGrenoble


This API depends on the gnome library, you need to have gnome libraries installed for this to work.

Something similar sudo apt-get install libgnome should do the trick i think (do not have my ubuntu desktop at hand to check the package name, try apt-cache search libgnome to find the real name if this does not work).

Note : you should specify which JVM you are using, I assume it's oracle JVM.

You could also give browserlaunch2 a try, yet it's rather old and I've never used it myself. As written on it's website it is meant to open the default browser on the supplied url :

BrowserLauncher2, a continuation of the BrowserLauncher project, is a library that facilitates opening a browser from a Java application and directing the browser to a supplied url. In most cases the browser opened will be the user's default browser.

BrowserLauncher launcher = new BrowserLauncher();
launcher.openURLinBrowser("http://www.google.com");

As BrowserLauncher2 is open source, you could also have a look at how it detects the default browser.

like image 39
Pierre Rust Avatar answered Nov 10 '22 17:11

Pierre Rust