Java 17 on the Raspberry Pi
As part of the Foojay Virtual OpenJDK 17+ JUG Tour, I was asked to present the state of Java and JavaFX 17 on the Raspberry Pi. So, a perfect opportunity to freshen up my #JavaOnRaspberryPi presentation with some hot-off-the-press version information.
In this article you can find more background information, the recording of the Manchester JUG of 27/08/2021 is available on YouTube.
In the past, I have been experimenting with Java 16 on the Raspberry Pi (see “Building OpenJDK from GitHub Sources on 64-bit Raspberry Pi”) but now that version 17 is available, it’s time to upgrade our Raspberry Pi with the upcoming new “long-term-supported” (LTS) version.
To be able to easily test and install different Java versions, I love using SDKMAN but unfortunately this isn’t available for 32bit systems. So, no problem, we start with a fresh Raspberry Pi and the 64bit OS version!
Setup a New Raspberry Pi with 64bit OS
Although the 64bit version is still not officially released at the time of writing (as described earlier in “Faster & More Reliable 64-bit OS on Raspberry Pi 4 with USB Boot”), there is a more regular updated version available on the download server of the Raspberry Pi Foundation.
For this post, I used the /raspios_arm64/images/
version of 2021-05-28 and "burned" it on a USB Flash Drive with the Raspberry Pi Imager tool. This is a Desktop version of Debian 10 customized for the Raspberry Pi, with minimal extra tools pre-installed. The full version with Java 11 and extra programs, is only available as a 32bit version in /raspios_full_armhf/
.
After booting we can check the version in the terminal:
SDKMAN
SDKMAN is very useful tool to quickly install a new Java version or switch between already installed versions. With a few terminal commands, we can install it on our Raspberry Pi.
OK nice, we have SDKMAN running on the Raspberry Pi now! There is an impressive list of Java editions you can install! This is the list on 23th of September 2021 you get with the command sdk list java
:
Let’s install the Temurin version 17 provided by adoptium.net (formerly known as adoptopenjdk.net).
Indeed sdk install java 17.0.0-tem
is all that's needed to switch to Java 17!
Early Access Java 17
As no official Java 17 is available at the time this article was written, an other approach is to install an early access version provided by jdk.java.net. At 23th of August an EA-version was available and could be installed based on this step-by-step description on opensource.com:
Now let’s make it easier to start Java:
Look at that, Java 17-ea on the Raspberry Pi! 😉
Visual Studio Code
Check “Java Development with VS Code on the Raspberry Pi” for more info about using VSC on the Raspberry Pi, but in short install like this:
Now let’s try the smallest Java program you can write to check and print the Java version…
And, finally, as we can run Java files without compiling them, since Java 11, we can just run it like this:
Run a Pi4J project
Now let’s see if we can run the minimal example project of the Pi4J project to control a LED and read a button state with some basic electronic components.
This is fully described on “Minimal example application”, but this is the TL;DR; version, open a terminal and run the following commands to install Maven, get the demo code, build and run:
Conclusion
As always, Java runs everywhere so no surprises here with version 17 on the Raspberry Pi! The Pi4J example application also runs without problems!
Artical originally published on foojay.io.
Other Java articles and Resources you may like