can not run java program on linux terminal [duplicate]
Possible Duplica开发者_如何学编程tes:
Exception in thread “main” java.lang.NoClassDefFoundError: DiServer <wrong name: ds/DiServer> java.lang.NoClassDefFoundError when i run java file from terminal
I have a program with multiple classes and compile them on the terminal with javac *.java
and then try to run the main file by simple doing java filename
but it spits out the following error. I don't know what it wants. Help will be appreciated.
Exception in thread "main" java.lang.NoClassDefFoundError: lab6 (wrong name: lab6/lab6)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
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)
The error message means that you tried to execute your class using java lab6
, but it's actually called lab6.lab6
(i.e. it's in a package called lab6
and its simple name is lab6
).
To execute it, you point your classpath to the directory containing the directory lab6
and execute java lab6.lab6
.
The easiest way is to go into that directory (whatever it is called) and execute java -cp . lab6.lab6
.
精彩评论