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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With