I want to auto run a .jar file after my Raspberry Pi boots up.
Normally I execute to .jar file with the following command (works great):
sudo java -classpath .:phidget21.jar -jar TestSensor.jar
(I can't simply use java -jar TestSensor.jar since the phidget21.jar needs to be appended to make the TestSensor.jar work properly)
Now, I want to execute the above command at the boot up of my raspberry pi.
As suggested in many places I tried to solve it with the rc.local file.
I added the following two lines:
cd /home/pi
sudo java -classpath .:phidget21.jar -jar TestSensor.jar
Unfortunately that doesn't work.
Even
cd /home/pi
sudo java -jar TestSensor.jar
Doesn't start the TestSensor.jar on a boot up.
What am I doing wrong? Any idea how to fix it?
Thanks
You could achieve that with crontab
. As root
using eg. crontab -e
(the recommended way of editing the crontab
file) you can add the line
@reboot /usr/bin/java -classpath /home/pi/:/home/pi/lib/phidget21.jar -jar /home/pi/TestSensor.jar
As indicated you may have to add full paths to java
, elements in the classpath and TestSensor.jar
. You should replace "my" paths with the actual locations of your java
and JARs.
Cheers,