Thứ Năm, 15 tháng 10, 2015

Run a java program in Ubuntu on startup.

To run a java program in Ubuntu on startup, there are many way to do.
We can put command line to the /etc/rc.local:

#sudo gedit /etc/rc.local

Then add your command to run java program:

======================================
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

java -cp /home/meo/Tools/ICM.jar com.icm.ConnectionManager &

exit 0

====================================== 

Note: & for running the program in background.

Source: http://unix.stackexchange.com/questions/123762/make-a-java-jar-file-jar-run-at-startup

How to run a jar file in command line?

Some ways to run a Jar file:
 
If you build a jar file as runnable, then the manifest will be created automatically. Otherwise you need to add manifest into  META-INF/MANIFEST.MF:
Main-Class: com.mypackage.MyClass (with a new line)
  
Now run a jar file:
1. java -cp path/to/file.jar my.classpath.ClassContainsMainMethod
2. java -jar <jar-file-name>.jar (with a runnable jar)