Daily Archives: April 5, 2015

Run class in jar file

Suppose we have below structured maven project.

After we build it by maven, it generates test-1.0.jar file in target folder. How do we run this App.class in jar?

We can run it by below command:
java -cp test-1.0.jar com.pli.project.test.App

In another case, if there are more than one jar file needed, we can specify more jar files. For example, below is the way how I run a batch job in command line:

windows:
java -cp “dependency-jars/*:SpringBatchLearn-1.0-SNAPSHOT.jar” org.springframework.batch.core.launch.support.CommandLineJobRunner springbatch-config.xml pliJob

linux:
java -cp “dependency-jars/*;SpringBatchLearn-1.0-SNAPSHOT.jar” org.springframework.batch.core.launch.support.CommandLineJobRunner springbatch-config.xml pliJob