Installing Java JDK with JavaFX on the Raspberry Pi
Java is still the #1 programming language (see https://www.tiobe.com/tiobe-index/) and it’s part of the full Raspbian OS (the default Raspberry Pi OS) that you can download from the Raspberry website. But if you want to use JavaFX on the Raspberry Pi to build beautiful user interfaces, you can switch to an other SDK version as descibed in this post.
Disclaimer: this article is only valid for Raspberry Pi’s with an ARMv7 or ARMv8 processor. In the Raspberry Pi specifications table on Wikipedia you get a clear overview of the Pi-types with this processor:
- Model A+, version 3
- Model B, version 2, 3 and 4
- Compute Module, version 3
Raspbian OS with Java 11
In the release notes of Raspbian you can see that the version of 2019–06–20 includes OpenJDK Java 11:
* Based on Debian Buster
* Oracle Java 7 and 8 replaced with OpenJDK 11
So if we start with a fresh new Raspbian OS we indeed get this Java version result:
$ java -version
openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Raspbian-1deb10u1)
OpenJDK Server VM (build 11.0.6+10-post-Raspbian-1deb10u1, mixed mode)
This means we are already good to start any Java 11 based program!
LibericaJDK to run JavaFX programs
As JavaFX is no longer part of the Java JDK (since version 11), running a JavaFX program on Raspberry Pi will not work out-of-the-box.
Luckily we can use the LibericaJDK which is provided by BellSoft. They have a version dedicated for the Raspberry Pi which includes JavaFX, so you will be able to run a JavaFX application with a simple “java -jar yourapp.jar” start command.
We only need the download link from their site to install an alternative Java JDK like this:
$ cd /home/pi
$ wget https://download.bell-sw.com/java/13/bellsoft-jdk13-linux-arm32-vfp-hflt.deb
$ sudo apt-get install ./bellsoft-jdk13-linux-arm32-vfp-hflt.deb
$ sudo update-alternatives --config javac
$ sudo update-alternatives --config java
When this is done, we can check the version again and it should look like this:
$ java --version
openjdk version "13-BellSoft" 2019-09-17
OpenJDK Runtime Environment (build 13-BellSoft+33)
OpenJDK Server VM (build 13-BellSoft+33, mixed mode)
On my test-Pi I even keep different versions of LibericaJDK and switching is very easy with “update-alternatives”.
Install scripts on GitHub
On Github, in the sources of my book “Getting started with Java on Raspberry Pi”, you can find install scripts for multiple versions of LibericaJDK which already contain the correct download link for each one.
And, If you like this video and want to learn more you can also check the full course here — Use Java and Java FX on a Raspberry PI
Other Programming Articles you may like
The 2020 Web Developer RoadMap
10 Reasons to Learn Python in 2020
10 Programming languages You can Learn in 2020
10 Tools Every Java Developer Should Know
10 Reasons to Learn Java Programming languages
10 Frameworks Java and Web Developer should learn in 2020
10 Tips to become a better Java Developer in 2020
Top 5 Java Frameworks to Learn in 2020
10 Testing Libraries Every Java Developer Should Know
What Java Programmers should learn in 2020?
Useful Tools, technologies, framework, and libraries Java programmers can learn in 2020
What Next for Senior Developers in Tech? Project Manager, Technical Architect or a DevOps Engineer
It’s time to think about the next level in your career.