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?

Thanks!

link|improve this question

75% accept rate
feedback

1 Answer

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.

link|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
feedback

Your Answer

 
or
required, but never shown

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