• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NoClassDefinitionFound...

 
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 751
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 751
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys! Navigating though the WEB-INF/classes directory and running

javac dir1/dir2/dir3/dir4/MyClass

solved the problem!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic