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

Rahul
  • 44,383
  • 11
  • 84
  • 103
GowthamIyer
  • 485
  • 1
  • 5
  • 17

2 Answers2

2

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

OlivierGrenoble
  • 3,803
  • 2
  • 18
  • 25
1

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.

Pierre Rust
  • 2,474
  • 18
  • 15