简体   繁体   English

java.exe -jar的其他jar文件

[英]Additional jar files for java.exe -jar

I run the following command: 我运行以下命令:

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 is inside dependency.jar. MyException位于dependency.jar中。 I also tried to replace -cp with -classpath. 我还尝试用-classpath替换-cp。 What do I do wrong? 我做错了什么?

The -cp options is ignored if you use -jar . 如果使用-jar-cp选项将被忽略。 If you need extra jar-files on the class-path, you should specify this in the Manifest of main.jar like this: 如果在类路径上需要额外的jar文件,则应在main.jar清单中指定此文件,如下所示:

Class-Path: dependency.jar

(Then you can run your program using java -jar main.jar .) (然后,您可以使用java -jar main.jar运行程序。)

Related questions: 相关问题:

Have you tried specifying the class path in the windows environment variable CLASSPATH ? 您是否尝试过在Windows环境变量CLASSPATH中指定类路径?

specify your environment variable CLASSPATH and put the value of your JAVA_HOME\\lib and (path to all your classes) and also include current directory by including (dot or period sign). 指定环境变量CLASSPATH并放置JAVA_HOME \\ lib和(所有类的路径)的值,并通过包含(点或点号)来包含当前目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM