我运行以下命令:
C:\Projects\java -cp ./dependency.jar -jar ./dist/main.jar Exception in thread "main" java.lang.NoClassDefFoundError: MyException Caused by: java.lang.ClassNotFoundException: MyException at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class: Main. Program will exit.
MyException在dependency.jar中。我也尝试用-classpath替换-cp。我做错了什么?
-cp如果使用,则将忽略这些选项-jar。如果在类路径上需要额外的jar文件,则应在清单中指定main.jar以下内容:
-cp
-jar
main.jar
Class-Path: dependency.jar
(然后,您可以使用来运行程序java -jar main.jar。)
java -jar main.jar