Last Updated: February 25, 2016
·
645
· karthic891

Run a class in jar file

Run a class in jar file:

java -cp <jar_file.jar> <class_in_jar_with_absolute_path>

Example:

MyJar.jar contents:

com.example.SomeClass1.class
com.example.SomeClass2.class

com.example.test.Main1.class
com.example.test.Main2.class
com.example.test.Main3.class

Note: Here com, example and test are folders that form the package/folder structure

Run Main2 as:

java -cp MyJar.jar com.example.test.Main2