I could not understand this error, the scenario is:
This is the directory structure:
classes/
root/
pkgmain/Cmain.class
pkg1/C1.class
pkg2/C2.class
The problem is when I try to run Cmain file (main() is in this file) from the following path, I get the error:
C:\Ravi\MakingJarFile\classes\root\pkgmain>java Cmain
Exception in thread "main" java.lang.NoClassDefFoundError: Cmain (wrong name: root/pkgmain/Cmain)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
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$000(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)
Could not find the main class: Cmain. Program will exit.**
What could be the solution for this problem, Thanks.
You need to provide the fully qualified class name, and do it from the root directory (or put that directory in the classpath):
or
You’re telling the
javacommand the full name of a class, and that’s what it’s looking for. When it finds a relevant class file it will check that the class within it really does have that fully-qualified name