Installation

Dependencies

Install JRE/JDK

If you have not already installed a Java runtime environment, please see the following article for a complete set of installation instructions for installing the Oracle JDK.
http://www.savagehomeautomation.com/pi-jdk

WiringPi Native Library

Pi4J depends on the WiringPi native library by Gordon Henderson. Please see the following page for more information on WiringPi.
https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/

No installation is required for Wiring Pi. Wiring Pi is embedded in the Pi4J native library.

Pi4J

Install Pi4J

Download a copy of the latest Pi4J Debian/Raspian installer package (.deb) file. You can use the following command on the Raspberry Pi's console to download the latest pi4j.jar build:
wget http://pi4j.googlecode.com/files/pi4j-0.0.4.deb

NOTE: If you have a previous version of Pi4J installed, please uninstall it first.

Once downloaded, use the following command to perform the installation:
sudo dpkg -i pi4j-0.0.4.deb

This will install the Pi4J libraries and example source files to:
/opt/pi4j/lib
/opt/pi4j/examples

When attempting to compile a Java program using the Pi4J libraries, make sure to include the Pi4J lib folder in the classpath:
javac -classpath .:classes:/opt/pi4j/lib/'*' ...

When attempting to start a Java program using the Pi4J libraries, make sure to include the Pi4J lib folder in the classpath:
sudo java -classpath .:classes:/opt/pi4j/lib/'*' ...

If you would like to explore the examples, you can compile all the examples with the following commands:
cd /opt/pi4j/examples
./build

Uninstall Pi4J

To uninstall Pi4J from your Raspberry Pi, use the following command:
sudo dpkg -r pi4j