This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
NoClassDefinitionFound means your classpath is wrong in someway. here are some suggestions about how to fix this. If you search through this and the beginner's forum you'll find lots of other advice. You might also have a glance at our FAQs.
For hints about what is missing go to the Navigator view in Eclipse, find the .classpath file within your project and open it up. Within that you will find the classpath that Eclipse is using when you run from within Eclipse. Compare that to what you have on the command line and you should find something missing. Note that there are different "kinds" of elements in Eclipse's classpath, you can figure out what they are from context. BTW, you probably don't want to change the .classpath file.
Joined: Sep 18, 2005
Hmmm... no luck...
E:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\zstats\WEB-INF\cl asses\dk\zmag\http\process>java -classpath . DailyUpdate Exception in thread "main" java.lang.NoClassDefFoundError: DailyUpdate (wrong na me: dk/zmag/http/process/DailyUpdate) 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.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 java.lang.ClassLoader.loadClassInternal(Unknown Source)
Even when I run a simple hello world program. This error appears. But when I try to remove the package keyword from the top of my source file it compiles and runs quite fine...
The compiler uses the package name to decide where to put the generated class file (that you probably know). The default classloader (the thing that actually opens the *.class file and puts in memory to run) uses the package name as a directory name.
To start the main method in class HelloWorld in package com.mycompany use something like:
in which case the classloader will look in the directory ./com/mycompany for a file named HelloWorld.class
If you don't have the package declared then the class is said to be in the default package (i.e. no name) and would be started something like this:
in which case the classloader will look in the current directory for a file named HelloWorld.class
Does that help?
Joined: Sep 18, 2005
Hi guys! Navigating though the WEB-INF/classes directory and running