You need Java 21 or newer to use Pi4J V3+. Please check the Prepare a Raspberry Pi and Install Java and Tools instructions. 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
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 (VSC) is the free IDE (Integrated Developer Environment) by Microsoft. It’s designed as a universal tool that you can use for multiple programming languages with extensions.
Visual Studio Code is available as a Raspberry Pi OS apt package. Use the following commands to install it:
$ sudo apt update
$ sudo apt install code -y