Desktop.getDesktop().open(file) on Ubuntu not working

Issue

I have a Java application, and when I use java.awt.Desktop:

Desktop.getDesktop().open(file);

It works fine on Windows (opens a file in my default program), but on Ubuntu (with openJdk 13), the Java application gets stuck and I do not even get any log error or anything. I have to force quit the app in order to recover.

The file path it correct, otherwise I would actually get an Exception. Also, isDesktopSupported a isSupported(Action.OPEN) returns true.

What can I do? Can I check some system settings or logs? Or perhaps get some logs from java.awt.Desktop? Or does this not work on Ubuntu/Linux?

Are there any alternatives?

Solution

From here:

In order to use the API, you have to call java.awt.EventQueue.invokeLater() and call methods of the Desktop class from a runnable passed to the invokeLater():

void fxEventHandler() {
   EQ.invokeLater(() -> {
      Desktop.open(...);
   });
}

Answered By – stove

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published