Running a java program as root on startup

Hi, I have a java program(GUI) with GPIO controls created in Netbeans IDE. I can run my program using “sudo java -jar path/to/my/program.jar”. I want to run the program on start up. I tried using “Startup Application Preference” but no success. Anyone can help me? Thanks in advance.

/home/pi/Desktop/dist/DPK.jar
(file path and filename)

HI @KrungKrungXD,

could you tell us what the name of the app is please, someone can maybe help you further if you tell us what it is you are trying to run. :smiley:

Startup Applications > Add > Browse > File System > usr > bin is the normal path to find the start-up command. :smiley:

@wolfman

/home/pi/Desktop/dist/DPK.jar

Thanks for the reply … Do I need to moved it in the bin folder?

Hi @KrungKrungXD,

I’ll bet your command would work in Startup Applications by just replacing sudo with gksu which is the GUI version to ask for your password to run as root.

Unfortunately, it may run a little silly because the desktop may be coming up and it WILL ask for a password.

There’s ways to reduce the strange startup it creates but eliminating the password would take some power scripting.

Hi @KrungKrungXD,

it might have helped had you have informed us that it is for Raspi!. :confused:

You have an answer here:

https://www.raspberrypi.org/forums/viewtopic.php?t=173987&p=1111848

I have edited your OP to reflect that your question is for Raspi. :smiley:

@Bill_MI

Any other advice to run the program without typing the password?

@wolfman

Sorry for the incomplete information, the link that you provided is me asking on the other forum.

Just some possible vectors.

I’ve used /etc/rc.local to do things like mount network drives on login but never for an interactive GUI in a DE. I’m assuming this .jar needs to interact with the desktop. In general, system programs have a user component for the GUI.

I’ll mention sudo’s -S option. Feel free to research but I’d never endorse it.

1 Like

You can use sudo for single commands without a password.
Have a look here and search for NOPASSWD.


After editing your sudoers file you can start your program / script from the startup applications
without to enter your password for the sudo command.
But be aware: This might be a security risk.

2 Likes