Java GUI support on Wayland

vinoth kumar picture vinoth kumar · Aug 29, 2016 · Viewed 9.9k times · Source

I want to include Java GUI support on my system which has only wayland backend supported. I tried to include OpenJDK-7-jre package, but it seems to have X11 dependency. I compiled ‘Openjre-8’ package successfully and included in my image. But, it can run only Java applications without GUI. When I try to run any JAVA SWING API based GUI program I get the following error:

Exception in thread "main" java.awt.HeadlessException                           
        at java.awt.GraphicsEnvironment.checkHeadless(Unknown Source)           
        at java.awt.Window.<init>(Unknown Source)                               
        at java.awt.Frame.<init>(Unknown Source)                                
        at java.awt.Frame.<init>(Unknown Source)                                
        at javax.swing.JFrame.<init>(Unknown Source)                            
        at GuiApp1.<init>(GuiApp1.java:25)                                      
        at GuiApp1.main(GuiApp1.java:20)  

Is it possible to run Java GUI programs on wayland? How do we do it?

Answer

Jamey Sharp picture Jamey Sharp · Sep 30, 2016

I found this question while wondering the same thing: I have a Java Swing application that I would like to run natively on Wayland. I don't know if that's possible, and the lack of other answers seems to indicate that it is not.

However, you absolutely can run a Swing application under XWayland, and run that under your preferred Wayland compositor. You may find that's good enough for your needs. It's working well for me in initial testing under the GNOME 3 compositor, at least.

Edit: on continuing my search, I found that the Wayland community had answered your question the same way on their mailing list, along with additional context. To save other readers the trouble, this post summarizes the situation as of August 2016: https://lists.freedesktop.org/archives/wayland-devel/2016-August/030832.html