GITHUB PROJECT: https://github.com/Pi4J/pi4j-jbang
Want to get started with Java programming on the Raspberry Pi?
JBang is a great way to create your first program to control electronic components connected to the GPIO pins. What is JBang?
As described on their website:
JBang lets Students, Educators and Professional Developers create, edit and run self-contained source-only Java programs with unprecedented ease.
JBang lets you do all this!
# Install JBang
$ curl -Ls https://sh.jbang.dev | bash -s - app setup
# Check JBang by requesting its version
$ jbang --version
0.109.0
# Install Visual Studio Code
$ sudo apt install code
The Pi4J JBang project on GitHub contains several examples to demonstrate both JBang and Pi4J. Each java
-file is a full-containing runnable JBang application. This means you don’t need Maven, Gradle, or other Java build tool.
To tell JBang that it must handle the file as a Java application and do some upfront preparation work, the first line in each file is: ///usr/bin/env jbang "$0" "$@" ; exit $?
.
When an application needs dependencies, they are defined inside the file itself in a line starting with //DEPS
. For instance, to use the Pi4J Core library: //DEPS com.pi4j:pi4j-core:2.3.0
.
Each of the provided examples contains more information about the wiring inside the file itself and are also explained here on the Pi4J website.
You can clone the project with the examples to your Raspberry Pi in the terminal with the following commands:
$ git clone https://github.com/Pi4J/pi4j-jbang
$ cd pi4j-jbang
The examples in the GitHub project are explained on these pages:
This approach to demonstrate Pi4J with JBang has been explained and demonstrated on Voxxed Days Brussels on May 23th, 2023.