Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I recently started programming my very first java project. An automatic alarm clock.

I did all the work and have now my compiled .class file. But to get it working, I need it to start everytime I restart my machine. So all I want to know is how to get Linux to start a Java class file every restart.

share|improve this question
Any particular distro? –  Ignacio Vazquez-Abrams Jul 6 '13 at 21:23
I use a raspberry pi. OS is raspbian I think –  xMaschx Jul 6 '13 at 21:32

1 Answer 1

up vote 0 down vote accepted

You have to reference your executable in /etc/rc.local file (or add a system startup service /etc/rc2.d: the Pi boots to runlevel 2).

There, you put a normal java invocation with full path (i.e. /usr/local/bin/java ... or /usr/bin/java ...).

If you want the output to be logged to a file, you either leverage syslog function or redirect the output to a logfile (or two separate logfiles, one for stdout log, one for error log), i.e.

/path/to/java -JAVA_OPTIONS your.class >> /var/log/logfile.log 2>> /var/log/logfile.err

The first time, run the command from the command line to verify it is properly working.

share|improve this answer
Where do I have to put my Main.class file? When it's in the ~ folder its not found. –  xMaschx Jul 7 '13 at 10:22
@xMaschx You can put it anywhere. You just need to type the path to it, if it's in ~ then use /path/to/java -JAVA_ARGS /home/YOURUSER/your.class –  handuel Jul 7 '13 at 10:44
Already tried it, but when I execute the command "/usr/bin/java -classpath javampd.jar:. /home/pi/Testing" it says "mainclass .home.pi.Testing could not be found. –  xMaschx Jul 7 '13 at 10:49
any suggestions? –  xMaschx Jul 7 '13 at 12:48
Read en.wikipedia.org/wiki/… –  september Jul 7 '13 at 16:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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