Wednesday, February 2, 2022

[SOLVED] How to install JavaFX on Raspberry Pi OS

Issue

I want to run .jar file with JavaFX packeages on Raspberry PI 1 Model B. JavaFX is not included in JDK 8 version for ARM. Hence I tried to install JavaFX by reference to the following web site. https://stackoverrun.com/ja/q/11146620

I succeeded to install JDK and move extracted files form a zip archive to JDK required folders. I tried to run two .jar files after that. The GUI of one .jar file is consisted of Swing package, the other is consisted of JavaFX package. The .jar file consisted of Swing package worked well, as shown in the following figure. Swing on Raspbian

On the other hand, the .jar file consisted of JavaFX package outputs errors or warnings as shown in the following figure. JavaFX on Raspbian

After these outputs, abnomal GUI without titlebar was desplayed. Consequently, minimizing, maxmizing/resizing closing and moving window are unable. Additionally, surroundings of window is filled with black. Displayed window of JavaFX on Raspbian

Of cource it is confirmed that these two .jar files worked well on Java 8 on windows 10 environment without errors. Swing on Windows 10 JavaFX on Windows 10

Note:As you know, Java 8 version for windows includes JavaFX libraries originally.

I want to solve this problem. My current OS and Java information is shown below. Running Environment

Thanks so much for your time.


Solution

Indeed almost all Linux JDKs for ARM now are for 64bit.

But Azul has a Zulu JDK you can start from: https://www.azul.com/downloads/zulu-community/?version=java-11-lts&os=linux&architecture=arm-32-bit-hf&package=jdk

$ cd /usr/lib/jvm
$ sudo wget https://cdn.azul.com/zulu-embedded/bin/zulu11.41.75-ca-jdk11.0.8-linux_aarch32hf.tar.gz
$ sudo tar -xzvf zulu11.41.75-ca-jdk11.0.8-linux_aarch32hf.tar.gz
$ sudo rm zulu11.41.75-ca-jdk11.0.8-linux_aarch32hf.tar.gz
$ ls -l
total 12
lrwxrwxrwx  1 root root   21 Jul 23 15:58 java-1.11.0-openjdk-armhf -> java-11-openjdk-armhf
drwxr-xr-x  9 root root 4096 Aug 20 11:41 java-11-openjdk-armhf
drwxr-xr-x  2 root root 4096 Aug 20 11:41 openjdk-11
drwxrwxr-x 10  111  122 4096 Jul 10 16:50 zulu11.41.75-ca-jdk11.0.8-linux_aarch32hf

$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/zulu11.41.75-ca-jdk11.0.8-linux_aarch32hf/bin/java 1
$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/zulu11.41.75-ca-jdk11.0.8-linux_aarch32hf/bin/javac 1

$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                                             Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-11-openjdk-armhf/bin/java                       1111      auto mode
  1            /usr/lib/jvm/java-11-openjdk-armhf/bin/java                       1111      manual mode
  2            /usr/lib/jvm/zulu11.41.75-ca-jdk11.0.8-linux_aarch32hf/bin/java   1         manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/zulu11.41.75-ca-jdk11.0.8-linux_aarch32hf/bin/java to provide /usr/bin/java (java) in manual mode

$ sudo update-alternatives --config javac
There are 2 choices for the alternative javac (providing /usr/bin/javac).

  Selection    Path                                                              Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-11-openjdk-armhf/bin/javac                       1111      auto mode
  1            /usr/lib/jvm/java-11-openjdk-armhf/bin/javac                       1111      manual mode
  2            /usr/lib/jvm/zulu11.41.75-ca-jdk11.0.8-linux_aarch32hf/bin/javac   1         manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/zulu11.41.75-ca-jdk11.0.8-linux_aarch32hf/bin/javac to provide /usr/bin/javac (javac) in manual mode

$ java -version
openjdk version "11.0.8" 2020-07-14 LTS
OpenJDK Runtime Environment Zulu11.41+75-CA (build 11.0.8+10-LTS)
OpenJDK Client VM Zulu11.41+75-CA (build 11.0.8+10-LTS, mixed mode)

Next step is installing JavaFX from https://gluonhq.com/products/javafx/ > "JavaFX armv6hf SDK"

$ cd /home/pi
$ wget -O javafx.zip https://gluonhq.com/download/javafx-11-0-2-sdk-armv6hf/
$ unzip javafx.zip
$ rm javafx.zip

When this is done, you can run your application with the following command:

$ sudo java --module-path /home/pi/armv6hf-sdk/lib --add-modules=javafx.controls -jar YOUR-APP.jar

For the full step-by-step, check this article on my blog: https://webtechie.be/post/2020-08-27-azul-zulu-java-11-and-gluon-javafx-11-on-armv6-raspberry-pi/



Answered By - Frank
Answer Checked By - Cary Denson (WPSolving Admin)