I admit I'm a complete noob at this, but I've done my homework on this site and I still can't get what I want to happen. I'm trying to get a .jar file to run at startup on a rasbpian installation. Let's call it startup.jar, it's in /home/pi/ so if I enter:

/usr/bin/java -jar /home/pi/startup.jar

at the command line, it works no matter which directory I'm in when I enter it. So from /home/pi I enter:

cat > startupscript << EOF
/usr/bin/java -jar /home/pi/startup.jar

Then I enter:

chmod u+x startupscript

Now if I go to /home/pi and type sh startupscript it does exactly what I want. So then I type

sudo nano /etc/rc.local

and before the exit line I add:

sh /home/pi/startupscript &

But startup.jar still doesn't start at startup.

I've also tried copying startupscript into /etc/init.d/ and entering "sudo update-rc.d startupscript default[s, tried it with/without the s here]" but no dice.

Again, I realize this is a noob question, but what am I missing? I'm sure it's something simple.


2 Answers 2


Make a systemd unit for starting your script. I do not have enough information of detailed dependencies from your python script but as template for your needs I suggest to start with:

rpi ~$ sudo systemctl --force --full edit myjavascript.service

In the editor insert these statements, save it and quit the editor:

Description=My Java Program



Check with systemctl cat myjavascript.service and systemctl status myjavascript.service. Enable the new service with:

rpi ~$ sudo systemctl enable myjavascript.service


If it doesn't work please give me feedback in a comment to optimize the answer.

  • Thanks very much for this comment, it pointed me in the right direction. What ended up working for me was creating an autostart directory in /home/pi/.config and adding a file called myautostart.desktop that runs it with the line "Exec=sh /home/pi/startupscript". This project took me in a different way than I expected but it's working. Thanks again. Jun 12, 2018 at 20:49

I don't know much about java, but the language shouldn't matter. update-rc.d is a SysV command, Raspbian has been systemd for years. You could write a systemd script, but this is complex.

The simplest solution is to use crontab to run the job on restart.

You will find lots of similar question on this site (don't look for java but startup. https://www.raspberrypi.org/documentation/linux/usage/cron.md shows how this can be done.

  • Thanks so much. I marked your comment as useful and it told me that I don't yet have enough reputation for that to matter. I appreciate you taking the time. I'll research/try this and update here how it goes. Thanks again for your reply. Jun 12, 2018 at 4:38
  • Update: I tried adding "@reboot sh /home/pi/startupscript" "@reboot /usr/bin/java -jar /home/pi/startup.jar" but no dice. Eventually I got it working by adding a file to /home/pi/.config/autostart, which is working for now. Thanks again for replying to my question, I know this board sees a million variations of "can't get something to open at startup" and I appreciate you taking the time. Jun 12, 2018 at 20:49

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.