gpt4 book ai didi

java - 为什么java -cp无法搜索到目录下的.jar?

转载 作者:行者123 更新时间:2023-12-01 14:38:35 25 4
gpt4 key购买 nike

我执行java -classpath .;C:\libtest\log4j-1.2.15.jar;C:\devtool\eclipse\plugins\org.junit_4.8.2.v4_8_2_v20110321-1705\*.jar; org.junit.runner.JUnitCore com.xu.MyClass执行我的 junit 测试中的所有方法。

但是不行,报错如下。

Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/runner/JU
tCore
Caused by: java.lang.ClassNotFoundException: org.junit.runner.JUnitCore
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: org.junit.runner.JUnitCore. Program will exit.

但是目录 C:\devtool\eclipse\plugins\org.junit_4.8.2.v4_8_2_v20110321-1705 包含具有此类的 junit.jar 。为什么会出现这种情况?

如果我执行java -classpath .;C:\libtest\log4j-1.2.15.jar;C:\devtool\eclipse\plugins\org.junit_4.8.2.v4_8_2_v20110321-1705\junit.jar ; org.junit.runner.JUnitCore com.xu.MyClass。

它有效。

我引用了java命令的文档。

 -classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.

最佳答案

如果您想使用通配符(*),我认为您应该将您的条目括在 Windows 中的“”和 UNIX 中的“”中。另请记住,只有 Java 6 之后才支持使用通配符

关于java - 为什么java -cp无法搜索到目录下的.jar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16227655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com