Felix Eder
Felix Eder

Reputation: 325

Can't execute java program on Raspberry Pi on startup

I use a Raspberry Pi 3 Model B with Raspbian Jessie.

I have a java program that I want to compile and run on start-up. I figured I need to launch it through /etc/rc.local. I have a command to compile the java-files and one command to run them.

sudo javac -cp /home/pi/Desktop/MultiSensor_v2.0_Java/opencv-3.2.0-java/build/bin/.jar /home/pi/Desktop/MultiSensor_v2.0_Java/.java

sudo java -Djava.library.path="/home/pi/Desktop/MultiSensor_v2.0_Java/opencv-3.2.0-java/build/lib" -cp "/home/pi/Desktop/MultiSensor_v2.0_Java/opencv-3.2.0-java/build/bin/opencv-320.jar:/home/pi/Desktop/MultiSensor_v2.0_Java/" Main &

When I run these commands from the terminal it works perfectly. I tried to put these commands in the /etc/rc.local file before exit 0. On reboot, the compilation works but the actual program never executes. How do I get my java program to run upon startup using the two commands above?

Upvotes: 2

Views: 1346

Answers (2)

Felix Eder
Felix Eder

Reputation: 325

I managed to solve it by doing a bash-script as @ILikeCOding said, but I had to change the location from were it was called.

I moved the bash-script to the root directory and edited the autostart script located in:

/home/pi/.config/lxsession/LXDE-pi/autostart

In that file, I added a line to launch my script. I think this works because the autostart-script launches when you log into your user and not on boot, therefore the program can launch properly. Not sure if that's the case, but it works so I'm happy.

Upvotes: 1

ILikeC0ding
ILikeC0ding

Reputation: 68

I had this problem, too. I solved it with the following workaround: I created a shell-script that runs the java programm. Then I called the shell-script on startup.

Upvotes: 3

Related Questions