Add the following CLASSPATH export to your environment file:
sudo nano /etc/environment
Here are the contents of my file:
JAVA_HOME="/opt/java/jdk1.8.0"
CLASSPATH=".:/opt/pi4j/lib/*"
Next, you need to allow the "sudo" command to retain the CLASSPATH environment variable when a command is executed via sudo.
Use this command to edit the file:
sudo nano /etc/sudoers
then add this line below the other "Defaults"
Defaults env_keep +="CLASSPATH"
Now reboot.
sudo reboot
After rebooting, you should be able to compile (javac) and execute (java) without having to explicitly include the classpath command line argument.
This is working on my system.
Thanks, Robert