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.
Stable, Secure, and Affordable Java
Azul Platform Core is the #1 Oracle Java alternative, offering OpenJDK support for more versions (including Java 6 & 7) and more configurations for the greatest business value and lowest TCO.
Download Here!So, a perfect opportunity to freshen up my #JavaOnRaspberryPi presentation with some hot-off-the-press versions.
UPDATE 2021-08-30: the recording of the presentation has been published 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 waiting around the corner, it's time to prepare our Raspberry Pi for 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:
$ lsb_release -d Description: Debian GNU/Linux 10 (buster) $ uname -a Linux raspberrypi 5.10.17-v8+ #1414 SMP PREEMPT Fri Apr 30 13:23:25 BST 2021 aarch64 GNU/Linux
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.
$ sudo apt install zip $ curl -s "https://get.sdkman.io" | bash $ source "$HOME/.sdkman/bin/sdkman-init.sh" $ sdk version ==== BROADCAST ================================================================= * 2021-08-20: gradle 6.9.1 available on SDKMAN! * 2021-08-19: springboot 2.5.4 available on SDKMAN! * 2021-08-19: springboot 2.4.10 available on SDKMAN! ================================================================================ SDKMAN 5.12.2
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
:
================================================================================ Available Java Versions ================================================================================ Vendor | Use | Version | Dist | Status | Identifier -------------------------------------------------------------------------------- AdoptOpenJDK | | 16.0.1.hs | adpt | | 16.0.1.hs-adpt | | 11.0.11.j9 | adpt | | 11.0.11.j9-adpt | | 11.0.11.hs | adpt | | 11.0.11.hs-adpt | | 8.0.292.j9 | adpt | | 8.0.292.j9-adpt | | 8.0.292.hs | adpt | | 8.0.292.hs-adpt | | 8.0.275+1.hs | adpt | | 8.0.275+1.hs-adpt | | 8.0.252.hs | adpt | | 8.0.252.hs-adpt Corretto | | 17.0.0.35.1 | amzn | | 17.0.0.35.1-amzn | | 16.0.2.7.1 | amzn | | 16.0.2.7.1-amzn | | 11.0.12.7.1 | amzn | | 11.0.12.7.1-amzn | | 8.302.08.1 | amzn | | 8.302.08.1-amzn | | 8.0.262 | amzn | | 8.0.262-amzn Dragonwell | | 11.0.9.4 | albba | | 11.0.9.4-albba GraalVM | | 21.2.0.r16 | grl | | 21.2.0.r16-grl | | 21.2.0.r11 | grl | | 21.2.0.r11-grl Java.net | | 18.ea.15 | open | | 18.ea.15-open | | 18.ea.2.lm | open | | 18.ea.2.lm-open | | 17 | open | | 17-open | | 16.0.2 | open | | 16.0.2-open | | 11.0.12 | open | | 11.0.12-open | | 11.0.11 | open | | 11.0.11-open | | 11.0.10 | open | | 11.0.10-open | | 8.0.302 | open | | 8.0.302-open | | 8.0.292 | open | | 8.0.292-open Liberica | | 17.0.0.fx | librca | | 17.0.0.fx-librca | | 17.0.0 | librca | | 17.0.0-librca | | 16.0.2.fx | librca | | 16.0.2.fx-librca | | 16.0.2 | librca | | 16.0.2-librca | | 11.0.12.fx | librca | | 11.0.12.fx-librca | | 11.0.12 | librca | | 11.0.12-librca | | 8.0.302 | librca | | 8.0.302-librca Liberica NIK | | 21.2 | nik | | 21.2-nik | | 21.1 | nik | | 21.1-nik | | 21.0.0.2 | nik | | 21.0.0.2-nik Microsoft | | 16.0.2.7.1 | ms | | 16.0.2.7.1-ms | | 11.0.12.7.1 | ms | | 11.0.12.7.1-ms Oracle | | 17 | oracle | | 17-oracle SapMachine | | 17 | sapmchn | | 17-sapmchn | | 16.0.2 | sapmchn | | 16.0.2-sapmchn | | 11.0.12 | sapmchn | | 11.0.12-sapmchn Semeru | | 16.0.2 | sem | | 16.0.2-sem | | 11.0.12 | sem | | 11.0.12-sem | | 8.0.302 | sem | | 8.0.302-sem Temurin | | 17.0.0 | tem | | 17.0.0-tem | | 16.0.2 | tem | | 16.0.2-tem | | 11.0.12 | tem | | 11.0.12-tem | | 8.0.302 | tem | | 8.0.302-tem Zulu | | 17.0.0 | zulu | | 17.0.0-zulu | | 16.0.2 | zulu | | 16.0.2-zulu | | 11.0.12 | zulu | | 11.0.12-zulu | | 8.0.302 | zulu | | 8.0.302-zulu ================================================================================ Use the Identifier for installation: $ sdk install java 11.0.3.hs-adpt ================================================================================
Let's install the Temurin version 17 provided by adoptium.net (formerly known as adoptopenjdk.net).
pi@raspberrypi:~ $ java -version openjdk version "11.0.12" 2021-07-20 OpenJDK Runtime Environment (build 11.0.12+7-post-Debian-2deb10u1) OpenJDK 64-Bit Server VM (build 11.0.12+7-post-Debian-2deb10u1, mixed mode) pi@raspberrypi:~ $ sdk install java 17.0.0-tem Downloading: java 17.0.0-tem ... Installing: java 17.0.0-tem Done installing! Setting java 17.0.0-tem as default. pi@raspberrypi:~ $ java -version openjdk version "17" 2021-09-14 OpenJDK Runtime Environment Temurin-17+35 (build 17+35) OpenJDK 64-Bit Server VM Temurin-17+35 (build 17+35, mixed mode, sharing)
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:
$ wget https://download.java.net/java/GA/jdk17/0d483333a00540d886896bac774ff48b/35/GPL/openjdk-17_linux-aarch64_bin.tar.gz $ mkdir ~/bin $ echo PATH=$PATH:$HOME/bin >> ~/.bashrc $ source ~/.bashrc $ tar --extract --file openjdk-17_linux-aarch64_bin.tar.gz --directory=$HOME/bin $ bin/jdk-17/bin/java -version openjdk version "17" 2021-09-14 OpenJDK Runtime Environment (build 17+35-2724) OpenJDK 64-Bit Server VM (build 17+35-2724, mixed mode, sharing)
Now let's make it easier to start Java:
$ sudo update-alternatives --install "/usr/bin/java" "java" "/home/pi/bin/jdk-17/bin/java" 1 $ java -version openjdk version "17" 2021-09-14 OpenJDK Runtime Environment (build 17+35-2724) OpenJDK 64-Bit Server VM (build 17+35-2724, mixed mode, sharing)
Look at that, Java 17 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:
$ sudo apt update $ sudo apt install code
Now let's try the smallest Java program you can write to check and print the Java version...
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World, greeting you with Java version: " + System.getProperty("java.version")); } }
And, finally, as we can run Java files without compiling them, since Java 11, we can just run it like this:
$ java HelloWorld.java Hello World, greeting you with Java version: 17
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:
$ sudo apt install maven $ git clone https://github.com/Pi4J/pi4j-example-minimal.git $ cd pi4j-example-minimal/ $ mvn clean package $ cd target/distribution $ ls -l $ sudo ./run.sh LED high LED low LED high Button was pressed for the 1th time LED low LED high Button was pressed for the 2th time LED low ... LED low LED high Button was pressed for the 5th time
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!
Got SDKMAN installed, but no Java is available for my Pi 4B 4GB. “sdk list java” shows no result. I can say “sdk list” and I see java, but if I say “sdk install java” it reports:
Stop! java 17.0.1-tem is not available. Possible causes:
* 17.0.1-tem is an invalid version
* java binaries are incompatible with your platform
* java has not been released yet
…strange…
You probably used the “default” Raspberry Pi OS which is 32-bit. Correct? Unfortunately, SDKMAN indeed doesn’t have a list of 32-bit ARM JDK versions, but working on it… see https://github.com/sdkman/sdkman-cli/issues/836
Alternative approach via terminal:
$ java -version
bash: java: command not found
$ sudo apt update
$ apt search openjdk
$ sudo apt install openjdk-11-jdk
$ java -version
openjdk version "11.0.13" 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-post-Raspbian-1deb11u1)
OpenJDK Server VM (build 11.0.13+8-post-Raspbian-1deb11u1, mixed mode)
Thanks so much for this! I noted that I need to copy the installed instance to a second location on my Pi for MultiMC to “see” the install, but these instruction were instrumental to getting Minecraft 1.18 on my Pi. I posted instructions at https://www.hackster.io/gulyasal/minecraft-1-18-2-java-edition-client-on-rpi-4-model-b-14ceca and of course gave you credit for these instructions. Thank you again!
SDKMAN can now be fully used on both 32- and 64-bit OS systems! See https://foojay.io/today/installing-java-with-sdkman-on-raspberry-pi/ for more info.
Thanks, I couldn’t get it installed. Sdk makes it so much easier!