简体   繁体   中英

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM