My code is organized in the following way

projectFolder/source/all .java files and
projectFolder/classes/all .class files

The class path is set to project/classes

Now when i compile my Main.java class from source folder, a Main.class is generated in classes folder.

Now when i try to run the program using java Main by navigating to corresponding classes folder i am getting the following error.

Exception in thread "main" java.lang.NoClassDefFoundError: Main (wrong name: ie/d
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:472)

Can anyone let me know where am i wrong ?

5 Years
Discussion Span
Last Post by ynwa

How did you get to this weird folder structure? Never seen

    • sources
      • java files
    • classes
      • class files

Usual project structure would be

    • src
      • main
        • java
          • YOUR_PACKAGES
        • resources
    • target
      • packaged JAR, WAR or any other deployable format
      • YOUR_PACKAGES, containing class files

where "target" is populated by your IDE (Eclipse, NEtBeans, etc) or by build tools like Ant, Maven etc

So would you care to explain how you got to such folder structure?


Hi, Thanks a lot for the reply.

I created the folder structure manually.

I have resolved this issue. The mistake i have done is while running the class files from classes folder, i have to mention the package structure also which i didn't the first time.

Wrong : ProjectFolder>java Main
Correct : ProjectFolder>java a.b.c.Main where a.b.c is the package structure.

Edited by ynwa: n/a

This question has already been answered. Start a new discussion instead.
Be sure to adhere to our posting rules.