2

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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I did a shell-script that made just this, but I didn't get it to work. But then I solved it by doing a similar thing. Will write a formal solution to the problem.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.