source:http://sddhn.blog.163.com/blog/static/128187792011102454152790/
If a single jar file is not referenced to another jar file, and Main-class is specified, you can run this way:
Java-jar Hello.jar
What to do if the executing JAR file references other jar files.
Here Hello.jar the log4j log.
JAVA-CP Log4j-1.2.14.jar-jar Hello.jar
This can be taken for granted, and in practice there will be classnotfoundexception.
Because the-jar option is used, the environment variable CLASSPATH and all classpath specified on the command line are ignored by the JVM
The correct mode of operation is as follows:
1,
JAVA-CP Lib\log4j-1.2.14.jar;hello.jar Com.dhn.Hello (Com.dhn.Hello main Class)
separated by semicolons (;) between multiple jars under Windows, and finally you need to specify the complete main class name in the Run JAR file
2,
Java-jar Hello.jar
However, you need to modify the MANIFEST.MF in the Hello.jar to specify the other jars that are needed at run time through the Class-path in MANIFEST.MF.
The other jars can be the current path or a subdirectory under the current path. Multiple jar files separated by spaces
Take the following MANIFEST.MF file as an example
manifest-version:1.0
Main-class:com.ibm.portalnews.entrance.main
Class-path:lib\commons-collections-3.2.jar Lib\commons-configuration-1.5.jar Lib\commons-lang-2.3.jar lib\ Commons-logging.jar Lib\dom4j-1.6.1.jar Lib\jaxen-1.1-beta-7.jar Lib\jdom.jar Lib\log4j-1.2.14.jar
Where manifest-version represents the version number, which is typically generated automatically by IDE tools such as Eclipse
Main-class is the main class of the jar file, the entry of the program
Class-path Specify the desired jar, multiple jars must be on one line, multiple jars separated by spaces, and if the referenced jar is in the subdirectory of the current directory, Windows uses \ to split, Linux under/split
The file must have a blank space after the colon, or there will be an error
The last line of the file must be a carriage return line break, or there will be an error