1. Embedded Documentation
2. Setting up the Raspberry Pi
There are plenty of configurations with different hardware and operating systems that require different versions of binaries, linked to different libraries. The default distribution of JavaFX 11 Embedded is tested on a Raspberry Pi 3 Model B, using the Raspian Stretch Lite distribution. JavaFX is capable of running on a large number of other hardware and operating systems, and you can contact us if you want information about a specific configuration.
The Raspberry Pi site contains clear documentation about the product itself. Installing an operating system for the Raspberry Pi is described at https://www.raspberrypi.org/documentation/installation/installing-images/README.md.
The following documentation has been tested to work with Raspbian Stretch Lite, a minimal image based on Debian Stretch, and with Raspbian Stretch with Desktop. Both can be downloaded from https://www.raspberrypi.org/downloads/raspbian/
We use Stretch Lite in this documentation, since it is a small distribution. We recommend doing your Java and JavaFX development on typical desktop or laptop systems. The resulting class files, jars and jmods, can be copied to the device when you’re happy with your work.
|If you have a different OS (e.g. pre-installed on your Pi), chances are high the properties we use here are not correct to get it working. Although JavaFX on embedded works with X11 as well, we want to demonstrate it works without X (using Dispman). Therefore, we recommend using Raspian Stretch Lite.|
After follow the instructions for installing the operating system on the device, you can boot the device and log in.
Typically, you want to access your Raspberry Pi using ssh. This can be done by activating SSH. Follow these instructions for enabling SSH on your device.
If you want to leverage the hardware acceleration of the GPU of your Pi, you have to give it enough memory. Using the raspi-config tool, you can determine how much memory is used by the GPU. We recommend at least 256M, depending of course on how graphics-intensive versus how cpu-intensive your application is.
The Stretch Lite distribution contains a minimal setup for the Raspberry Pi. In order to run graphical software like JavaFX, we need to install some additional packages. Executing the following commands on the Raspberry Pi will achieve this:
sudo apt-get update sudo apt-get install libgtk2.0.0 sudo apt-get install libxtst6 cd /usr/lib sudo ln -s /opt/vc/lib/libbrcmEGL.so libEGL.so sudo ln -s /opt/vc/lib/libbrcmGLESv2.so libGLESv2.so
3. Installing Java
There are a number of options if you want to run Java on your Raspberry Pi. If you want to run a Java 11 distribution, completely based on OpenJDK, with integrated JIT (hotspot), we highly recommend Liberica JDK 11-preview.
tar.gz file, move it to
/opt and untar it using
tar. You can do this on
your device as follows:
wget https://github.com/bell-sw/Liberica/releases/download/jdk11%2B28/bellsoft-jdk11+28-linux-arm32-vfp-hflt.tar.gz sudo mv bellsoft-jdk11+28-linux-arm32-vfp-hflt.tar.gz /opt cd /opt sudo tar -xvzf bellsoft-jdk11+28-linux-arm32-vfp-hflt.tar.gz
Optionally you can remove the
sudo rm bellsoft-jdk11+28-linux-arm32-vfp-hflt.tar.gz
You can check if the Java installation was successful, by asking its version:
pi@raspberrypi:~ $ /opt/jdk-11/bin/java -version openjdk version "11-BellSoft" 2018-09-25 OpenJDK Runtime Environment (build 11-BellSoft+0) OpenJDK Server VM (build 11-BellSoft+0, mixed mode)
Now that Java has been installed successfully, you can move to the next step: Installing JavaFX.
4. Installing JavaFX
JavaFX 11 Early Access (11-ea) builds can be downloaded from https://gluonhq.com/products/javafx/
The JavaFX 11 Early Access build for Arm 32/Linux platforms works very well with the BellSoft Liberica JDK for the Raspberry Pi.
Download the SDK, move it to
/opt and unzip it:
wget -O armv6hf-sdk-11-ea+25.zip http://gluonhq.com/download/javafx-11-ea-sdk-armv6hf sudo mv armv6hf-sdk-11-ea+25.zip /opt cd /opt sudo unzip armv6hf-sdk-11-ea+25.zip
Optionally you can remove the zip file:
sudo rm armv6hf-sdk-11-ea+25.zip
We can now run our first JavaFX application on Raspberry Pi.
5. Run demo app
As a very first demo, we will show how you can run the MaryHadALittleLambda application on a recent Pi, with Java 11 and JavaFX 11. This application was created in 2014, in order to demonstrate the use of lambda’s. The author, Stephen Chin, wrote a blogpost about this.
The application was demonstrated on embedded devices as well.
The original code of the application is at https://github.com/steveonjava/MaryHadALittleLambda. We forked it and made some minor modifications in order to make it work with the JavaFX 9 and Java 9 APIs. The new code is at https://github.com/gluonhq/MaryHadALittleLambda.
It is important to mention that you would typically do all your development on your development system (desktop or laptop). You can use your IDE and common tools to create, compile and test applications. Once you are happy with the result, you can transfer your class files over to the embedded device, and run them there.
5.1. Download code
The first step is to get the code to your development system and to compile the application.
|it is highly recommended doing this on your desktop/laptop, and not on your Raspberry Pi, as it requires much more software than typically needed on embedded devices.|
git clone https://github.com/gluonhq/MaryHadALittleLambda.git cd MaryHadALittleLambda mvn clean compile
It is good practice to test your application on desktop or laptop before transfering the class files to your device. You can run the application on desktop using
You should see the application running now.
Quit the application, and check if the class files are in the target/classes directory. There should be about 20 classfiles in the sample package.
5.2. Install the class files on the device
You can now copy the classes from your development system to the Raspberry Pi, e.g.
cd target scp -r classes pi@pi:/home/pi
5.3. Run the application on the device
Now, log in via ssh to your Raspberry Pi and run the application.
sudo /opt/jdk-11/bin/java --module-path=/opt/armv6hf-sdk/lib --add-modules=javafx.controls -cp classes/ -Dprism.verbose=true -Dembedded=monocle -Dglass.platform=Monocle sample.Main
Make sure to replace classes with the place where you copied the classes to.