Cannot run Java jar file in Wayland-only Fedora 40

Hello All,

Coming from the Ubuntu and Arch ecosystems, I was attracted to the Wayland-only approach of Fedora 40 KDE. I am aware that Wayland cannot fully replace X11 yet, but I was shocked to discover that it cannot even run Java graphical applications! Attempting to run a couple of typical jar files with java -jar filename, I got the following error:

Exception in thread "main" java.awt.HeadlessException: No X11 DISPLAY variable was set, or no heaadful library support was found, but this program performed an operation which requires it.

Fedora 40 comes with OpenJDK Runtime 21.0.2 preinstalled, and “Wayland to X11 Video bridge” is active to the tray. Has anyone faced the same issue? How about Project Wakefield, the Wayland JDK? Any experience with compiling it and using it?

Regards,
Jordan

I frequently run my java apps on my Fedora 40 system, some are GUI based and work fine. A lot are even old, written over a decade ago for a couple. It seems from the erorr that you have the headless java installed, you may need the actual full JDK installed. Try a dnf search openjdk to get a list of the openjdk packages available and install the appropriate one for you.

3 Likes

Hi Stephen,
Thank you for your reply, you were right. I installed the full Java-21-OpenJDK, and now jar files are running smoothly through the terminal. However, to run a jar file through the GUI, I had to manually create an OpenJDK desktop entry. Do you have any idea why it was not auto-created after the OpenJDK installation?
Regards,
Jordan

I don’t understand why it would be. Perhaps you could enlighten me on that. It is after all a command line usage tool the java runtime, and has many options.

Having just upgraded from Fedora 39 to 40, it seems the headless openjdk becomes the default post upgrade.

Run:
$ rpm -qa | grep openjdk | sort
java-17-openjdk-17.0.10.0.7-3.fc40.x86_64
java-17-openjdk-headless-17.0.10.0.7-3.fc40.x86_64
java-21-openjdk-headless-21.0.2.0.13-3.fc40.x86_64

The quickest fix appears to just be:
sudo dnf install java-21-openjdk

Now various Java apps all work fine again.

4 Likes