java -jar java -cp and usage

java -jar

java -jar myClass.jar

  • When the command is executed, it will use the directory META-INF \ MANIFEST.MF file,
  • In that document, there is a parameter called Main-Class, which describes the class java -jar command execution

java -jar *.jar param1 param2

  • Run jar package, it will automatically query defined mainfest startup class package jar and run

  • param1, param2 as the main method parameters of time to fill

java -cp

  • java -cp and -classpath as other classes classes specified path running over this, usually library, jar package and the like, need the full path to the jar package,

  • window on the semicolon ";"

  • Semicolon on linux ":"

java -cp .;myClass.jar packname.mainclassname

  • Expression support wildcards, such as:

  • java -cp .;c:\classes01\myClass.jar;c:\classes02*.jar
    packname.mainclassname

java -cp lib / *; etc / param1 param2 com.Start

  • Add all the jar files in the lib and all the configuration files in the classpath etc
  • Looking com.Start and class (main method in class) and run in the classpath
  • param1, param2 as the main method parameters of time to fill

Note: jar file import classpath, wildcards can not be written .jar, or only use 123 *
Note: The configuration file introduction of classpath, the directory can only be written to / can not add *

Guess you like

Origin blog.csdn.net/weixin_42625143/article/details/95207074