11

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?

vinoth kumar
  • 133
  • 1
  • 8

3 Answers3

6

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

Jamey Sharp
  • 7,823
  • 2
  • 27
  • 42
  • 1
    I'm the author of that mail. In the meanwhile I've created a monocle port of javafx to wayland. More information here: https://github.com/udevbe/wayland-javafx – Zubzub Oct 06 '16 at 18:19
  • @Zubzub there is any solution for swing ? – Xan Oct 23 '17 at 09:31
  • 1
    @Xan Yes, redhat has a swing port for wayland.http://mail.openjdk.java.net/pipermail/caciocavallo-dev/2016-August/000558.html However, I don't know how well it works, or how easy it is to set up. – Zubzub Oct 24 '17 at 12:22
  • Progress seems good https://bugs.eclipse.org/bugs/show_bug.cgi?id=516841 – user1133275 Dec 24 '17 at 09:41
  • Do you know if the answer changed? I'd like to run a Java app with native wayland (not xwayland) but I don't know if it is possible. – Boiethios Dec 12 '20 at 13:12
1

This is kinda possible. AWT stands for "abstract" window toolkit. There are several extensions to AWT where the peer is QT or GTK instead of the default JDK.

Qt: https://cvs.savannah.gnu.org/viewvc/classpath/classpath/gnu/java/awt/peer/qt/

Gtk: https://cvs.savannah.gnu.org/viewvc/classpath/classpath/gnu/java/awt/peer/gtk/

Note these sources are old and might need some revisions to work with latest JDK.

Peter Quiring
  • 1,488
  • 1
  • 12
  • 19
1

I solved the problem using the cacio-wayland @Zubzub posted as a comment on another answer.

Since the program I wanted to use (IntelliJ IDEA) requires JDK >=11, I had to apply some changes to the cacio-shared subdirectory and adapt cacio-wayland accordingly to run on JDK11:

https://github.com/petabyteboy/caciocavallo/commit/81d3254699f6caaa1e9957cae47703e0b18de870

You can clone my repository, build the libraries and use them to start your application. In this example I start JD-GUI:

# make sure you have the following things installed: openjdk jdk11, cairo, wayland, libxkbcommon, maven, git

git clone https://github.com/petabyteboy/caciocavallo
cd caciocavallo

mvn clean install
# it may fail to generate javadocs, but as long as cacio-wayland/target/cacio-wayland-1.10-SNAPSHOT.jar is generated it should be fine

# the generated native library needs to be renamed to be found at runtime
mkdir natives
cp cacio-wayland/target/nar/cacio-wayland-1.10-SNAPSHOT-amd64-Linux-gpp-jni/lib/amd64-Linux-gpp/jni/libcacio-wayland-1.10-SNAPSHOT.so natives/libcacio-wayland.so

java \
  -cp $PWD/cacio-shared/target/cacio-shared-1.10-SNAPSHOT.jar:$PWD/cacio-wayland/target/cacio-wayland-1.10-SNAPSHOT.jar:/usr/share/jd-gui/jd-gui-1.6.6.jar \
  -Dawt.toolkit=net.java.openjdk.cacio.wayland.WaylandToolkit \
  -Djava.awt.graphicsenv=net.java.openjdk.cacio.wayland.WaylandGraphicsEnvironment  \
  -Djava.library.path=$PWD/natives \
  org.jd.gui.App

If it gives a SIGSEGV crash in your wayland compositor, try in Weston.

  • I also wanted it mostly for JetBrains IDEs. Here https://youtrack.jetbrains.com/issue/JBR-3206 they say that it will have native wayland support. Also, some info on java hidpi is here https://wiki.archlinux.org/index.php/HiDPI#Java_applications – Ashark Apr 25 '21 at 18:43