<< PiJava - Part 6: JavaFX 11 application on Raspberry PI with TilesFX and GPIO
PiJava - Part 5: Running the minimal JavaFX 11 application on Raspberry PI
TL;DR; We can run the minimal JavaFX jar from the previous blog post with either JavaFX as module, and "the old fashioned" way with the Java 11.0.2 version of BellSoft which includes JavaFX.In part 2 of this blog series Java 11 was successfully installed on a PI.
And in part 4 a running Java FX jar was generated on a PC.
Time to move back to the PI...
Install Java FX 11 moduleAs Java FX has become a separate project and is no longer a part of Java itself, it needs to be installed next to it. Based on the article of GluonHQ which was my starting point for this blog series, I created a script you can use to download JavaFX and install it in "/opt/", or you can run these commands:
# Make sure we are in the home directory cd /home/pi # Download the JavaFX 11 build from GluonHQ wget -O armv6hf-sdk-11-ea+25.zip http://gluonhq.com/download/javafx-11-ea-sdk-armv6hf # Move the downloaded file to /opt sudo mv armv6hf-sdk-11-ea+25.zip /opt # Use the /opt directory cd /opt # Unzip the downloaded file sudo unzip armv6hf-sdk-11-ea+25.zip # Remove the downloaded file sudo rm armv6hf-sdk-11-ea+25.zip
Run the JavaFX .jar applicationSimilar to the Windows start script, a script is available to start the application on the PI, or you can run yourself in terminal with this command:
sudo /opt/jdk-11/bin/java \ --module-path /opt/armv6hf-sdk/lib \ --add-modules=javafx.controls \ -jar MinimalJavaFx11Application-0.1-SNAPSHOT.jarBasically these are the parts in the command if we first move to the directory where the jar-file is located.
- to get it starting correctly
- the location where we installed Java 11
- "--module-path /opt/armv6hf-sdk/lib"
- the location where we installed JavaFX 11
- the JavaFX modules we actually need
- "-jar MinimalJavaFx11Application-0.1-SNAPSHOT.jar"
- the jar application we want to start
It's alive!And yes, without any extra effort, the application (which is only 6kb BTW) created with Maven on a (Windows) PC runs on the PI!
Alternative: BellSoft Java 11.0.2
During my testing for this blog I received a mail from GluonHQ with more info of JavaFX on PI with the news there was a new Java 11.0.2 version available from BellSoft which again includes JavaFX so the separate download we did before is no longer needed.
To be able to test this next to the previous flow, I created and used a different script to install this 11.0.2 version of Java for PI.
# Make sure we are in the home directory cd /home/pi # Download the Java 11.0.2 distribution from BellSoft wget https://download.bell-sw.com/java/11.0.2/bellsoft-jdk11.0.2-linux-arm32-vfp-hflt.tar.gz # Move the downloaded file to /opt sudo mv bellsoft-jdk11.0.2-linux-arm32-vfp-hflt.tar.gz /opt # Use the /opt directory cd /opt # Untar the downloaded file sudo tar -xvzf bellsoft-jdk11.0.2-linux-arm32-vfp-hflt.tar.gz # Remove the downloaded file sudo rm bellsoft-jdk11.0.2-linux-arm32-vfp-hflt.tar.gzAfter this we can also request the version of this new Java version with this result:
Starting the jar with 11.0.2
As JavaFX is part of Java in this version, our start script becomes a lot easier as we don't need to provide the module settings:
sudo /opt/jdk-11.0.2/bin/java -jar ../out/MinimalJavaFx11Application-0.1-SNAPSHOT.jarThe application runs perfectly but full-screen without any option to exit, as the application toolbar is not added. Something to further research why this is different, but adding a "Close" application button to the application solves this for now...
How it looks
When taking a screenshot while the application runs, with following command (a delay of 20" so the application can be started from another terminal), the JavaFX application is not captured at all and we only see the terminals I had running for the screenshot tool and starting the JavaFX application.
scrot -d 20
But this is what is actually on the screen:
ConclusionWe can run the minimal JavaFX jar from the previous blog post with either JavaFX as module, and "the old fashioned" way with the Java 11.0.2 version of BellSoft which includes JavaFX.
One step left now... A more extended JavaFX application which is also able to toggle a GPIO. Some more challenges ahead ;-)