10/24/2012

Java execute jar file using -cp

-cp : To tell java where to find the .class file.

So after you have packaged your project into jar file, then execute:

java -cp .;myClass.jar packname.mainclassname

If there are multiple jar file that need to be referenced, then

java -cp .;c:/classes/myClass.jar;d:/classes/*.jar packname.mainclassname

use ";" to separate each jar file.

packname.mainclassname is used to specify the entrance of the code.

If you code has multiple main method, it's used to specify which main method is to be executed.

No comments:

Post a Comment