Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes NoClassDefinitionFound... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "NoClassDefinitionFound..." Watch "NoClassDefinitionFound..." New topic
Author

NoClassDefinitionFound...

Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
This is very funny... I'm trying to execute an application with a main method and I swear I have tried every possible means like putting the classpath option in java command.

Here is what I have in my CLASSPATH environment variable


.;E:\Program Files\Java\jre1.5.0_08\lib\ext\QTJava.zip;mysql-connector-java-3.1.13-bin.jar;E:\Program Files\Java\jre1.5.0_06\lib\ext;E:\Program Files\Java\jre1.5.0_06\lib\ext\jfreechart-1.0.2.jar;%CLASSPATH%



It works well in Eclipse when I run the app but not in the commandline. Hmmm... Maybe I need some rest... But please give some answers. Thanks!


SCJP 1.5
http://devpinoy.org/blogs/lamia/ - http://everypesocounts.com/
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Chris Beckey
Ranch Hand

Joined: Jun 09, 2006
Posts: 116

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.
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
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...
Chris Beckey
Ranch Hand

Joined: Jun 09, 2006
Posts: 116

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?
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
Hi guys! Navigating though the WEB-INF/classes directory and running

javac dir1/dir2/dir3/dir4/MyClass

solved the problem!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: NoClassDefinitionFound...