最近遇到这个事情,发现java的帮助写得有多烂,先不说那个著名 "Jar cfvm output.jar manifest.mf -C classes_path"的问题,根本不用加-C。
这个-jar的问题也确实太让人头疼, 后来看了下面才知道
并且要写成 java -Xbootclasspath:"依赖库路径" -jar xxx.jar
其中注意两点
1)"依赖库路径"当中多个路径或者jar包在windows下用; 分隔,unix下用: 分隔
2)-Xbootclasspath/a 和 -jar的顺序不能颠倒,不能写成 java -jar xxx.jar -Xbootclasspath/a:"依赖库路径" 否则在一些系统下面依然无法启动
http://stackoverflow.com/questions/250166/noclassdeffounderror-while-trying-to-run-my-jar-with-java-exe-jar-whats-wron
The -jar option is mutually exclusive of -classpath. See an old description here
-jar
Execute a program encapsulated in a JAR file. The first argument is the name of a JAR file instead of a startup class name. In order for this option to work, the manifest of the JAR file must contain a line of the form Main-Class: classname. Here, classname identifies the class having the public static void main(String[] args) method that serves as your application's starting point.
See the Jar tool reference page and the Jar trail of the Java Tutorial for information about working with Jar files and Jar-file manifests.
When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.
A quick and dirty hack is to append your classpath to the bootstrap classpath:
-Xbootclasspath/a:path
Specify a colon-separated path of directires, JAR archives, and ZIP archives to append to the default bootstrap class path.
However, as @Dan rightly says, the correct solution is to ensure your JARs Manifest contains the classpath for all JARs it will need.