Java Development

Java on the Raspberry Pi

Please check the Prepare a Raspberry Pi and Install Java and Tools instructions.

You need Java 21 or newer to use Pi4J V3+. On a board with ARMv7 or ARMv8 you will get this result:

$ java -version
openjdk version "21.0.5" 2024-10-15 LTS
OpenJDK Runtime Environment Zulu21.38+21-CA (build 21.0.5+11-LTS)
OpenJDK 64-Bit Server VM Zulu21.38+21-CA (build 21.0.5+11-LTS, mixed mode, sharing)

Keep in mind this version is only compatible with ARMv7 or higher and doesn’t support all Raspberry Pi board versions. If you have a Raspberry Pi A (version 3), B (version 2 or higher), or Compute (version 3 or higher), you are good to go! For all other boards, or if you get the error below, you will need some additional steps that are described on Java for ARMv6/7/8.

$ java -version
Error occurred during initialization of VM
Server VM is only supported on ARMv7+ VFP

Maven

If you followed the steps described on Prepare a Raspberry Pi and Install Java and Tools, you already have Mave installed.

Pi4J is using Maven as build tool, this allows you to compile your code with the required modules into JAR-file thanks to the pom.xml configuration file which you can find in the root of a project. We need to install Maven and can do this with a single command, after which we can immediately check the installation by requesting the version:

$ sudo apt install maven
$ mvn -v
Apache Maven 3.6.0
Maven home: /usr/share/maven

Visual Studio Code

Please check Install Visual Studio Code for more info if you want to develop Java code directly on the Raspberry Pi.