我试过四处寻找,但找不到任何适合我的情况的答案。
当我使用 IDE 时,我可以很好地运行文件 CB.java。该文件依赖于 cs2.jar 中指定的类。这是其目录的内容。
02/12/2013 03:43 PM <DIR> .
02/12/2013 03:43 PM <DIR> ..
02/12/2013 03:45 PM 2,226 CB.class
02/12/2013 01:21 PM 2,164 CB.java
02/12/2013 03:43 PM 71,128 cs2.jar
3 File(s) 75,518 bytes
2 Dir(s) 408,977,362,944 bytes free
当我从 IDE 运行它时,CB.java 工作得很好。java CB
但是,当我在命令行中尝试时,我得到:
Exception in thread "main" java.lang.NoClassDefFoundError: sn/visual/JRect
angle
Caused by: java.lang.ClassNotFoundException: sn.visual.JRectangle
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: CB. Program will exit.
此外,我尝试使用以下建议向类路径添加一些内容:
>java -cp C:\Users\...blah blah blah...\Software_Engineering cs2
Exception in thread "main" java.lang.NoClassDefFoundError: cs2
Caused by: java.lang.ClassNotFoundException: cs2
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: cs2. Program will exit.
为什么我的 IDE 很聪明,但我的命令行却不聪明?
谢谢你。