我一直在尝试编译一个包含 2 个类(可以更多)的项目。这两个类位于我正在处理的同一目录中。我运行以下命令:
C:\Users\Me\Java>javac -d 类 -cp 类 *.java
包文件:cweek.java & nweek.java
package Hello;
public class cweek
{
public static void main(String[] args)
{
nweek.printmeth();
}
}
nweek.java
package Hello;
public class nweek
{
public static void printmeth()
{
System.out.println("I'm here");
}
}
现在我去 C:\Users\Me\Java\Classes\Hello 并尝试尝试“java cweek”命令,我收到以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: cweek (wrong name: Hello/cweek)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
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)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)