Take the 2-minute tour ×

I have two PCs, PC_1 running Debian5, PC_2 running Windows, I need to have PC_1 to start a Jar file automatically during startup.

When I put a script file to execute the Jar file in /etc/init.d, the startup hang at terminal screen (before into normal GUI screen of debian) as the Jar file is in infinite loop (constantly running checks).

When I put the script file in /etc/rc.local, somehow I manage to get it execute after GUI screen is shown, but it is run as background process, which the JFrame of the Jar file is not display.

May I know if there is any way to run the Jar file as Root and in foreground so that the GUI will display?

Reason of I required program to run as root is because I need to access serial port. So... ya, I need Root permission.

share|improve this question

migrated from stackoverflow.com May 12 '12 at 6:40

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers

up vote 1 down vote accepted

Please do not run things as root, especially not Java programs. If you really need root-resources, such as listening to < 1024 port, then use a separate program for that, like apache and hand off the communication to your java file through sockets or other port.

You can put stuff in ~/.xinitrc of a user to run when the Xorg server (gui screen) starts up. Look also if you have /etc/X11/Xsession.d/startup-local and put the run script there.

share|improve this answer
Thanks. But I need to access serial port. therefore I require root access. I will try to see your suggestions, thank you so much. –  Ghost_000_cs May 12 '12 at 2:08
Can you explain why you think that especially Java programs are critical to run as root? Compared to what - python, C, C++, php? –  user unknown May 12 '12 at 2:56
Because my program which accessing serial port is written in Java. To me, Java seems to be easier to run on Linux as compared to C, C++. Furthermore, I am not familiar with python and php. –  Ghost_000_cs May 13 '12 at 3:45
@Ghost_000_cs: I didn't ask you why you prefer Java over C, but Antonio, who hasn't an account here, and gets no information about new comments. –  user unknown May 18 '12 at 10:12
Can explain your question again? Cos that's what my understanding to your question. The reason of my Java program required root is already stated. –  Ghost_000_cs May 19 '12 at 3:18
add comment

During boot, X11 isn't up and running, so starting a JFrame is not possible.

If a user logs in, he owns the desktop, and his Xauthority is needed to use X11. Do you have an automatic login? Or does X11 show you a login screen?

You can start a program in the users autostart, and fix permissions in the sudoers file.

share|improve this answer
My computer doesn't require login, it will go into the X11 straight. I will try this method as well. –  Ghost_000_cs May 13 '12 at 3:43
May I know how to fix the permissions in sudoers file? –  Ghost_000_cs May 18 '12 at 7:35
@Ghost_000_cs: ad 1) You automatically login as one user, don't you? Then add the program to the autostarted programs of that user. I guess - ad 2) instead of 'and fixing' I should have used 'and setting up '. To setup the sudoers file, read the manpage first, then ask a specific, new question. You can link to this thread for background information, to not repeat yourself. –  user unknown May 18 '12 at 10:10
ok, thank you. I will search for more details. –  Ghost_000_cs May 19 '12 at 3:20
add comment

Your Answer


