Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 have a small java project that handle connections. In order to run it from the terminal I have to cd into the folder that contains the source and run the following command:

java -cp classes com.packagename.mainclass

Where classes is the folder that contains the classes.

I want ubuntu to run this application on startup, is there a Java command I can use? Or am I just better off creating a shell script?


share|improve this question

On system boot:

Add to the end of /etc/rc.local:

(cd ~your_username/path_to_source/ && sudo -u your_username java -cp ...) &

(It might be better to create an Upstart job instead.)

On logon:

Open "System - Preferences - Startup Programs" (gnome-session-preferences) and add your program there.

share|improve this answer
Can you add a java program to Startup programs, I assume it needs to be compiled to a JAR first? – Christopher Gwilliams Apr 28 '11 at 13:52
@Christopher: But you can add the java command. – grawity Apr 28 '11 at 14:08

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.