Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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 – w4etwetewtwet 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .