I installed jdk on my system. I set the classpath too. When I tried to run the program its giving NoClassDefFoundError. Its compiling the program and generated the class file. Why the JVM is unable to find out my class file even though it exists? When I type Java at the command prompt I am getting the list of attributes. I verified the class names given in the program and the name of the file. Both are same.
What value do you have for your CLASSPATH environmnet variable? Did you put a "package" statement at the top of your .java file? What directory was your .class file compiled into? What is the current directory?
All of the class files needed for your program have to be directories named after their package under a directory on your class path. For instance let's say your .java file is something like...
You can make the Java compiler create the package directory structure under the current directory by specifying the output directory with the -d option:
That will make a Suresh directory and put Kumar.class there.
Since the direcotyr you're in has a directory for the Suresh package, then it's the one that has to be on your class path. You can either set the CLASSPATH env var or use the -classpath option:
Notice that . is on the CLASSPATH, but ./Suresh isn't.
If you want to run this while in a completely different directory, then you have supply the absolute or relative path to where the root of your package directory structure is. For instance if the Suresh directory is a subdirectory under the c:\Vallabhaneni directory, then you could do the following (on a Windows machine):
That's the simple case. You can use jar files to package up a bunch of class and other files, but you should get the discreet file case working first. [ August 10, 2005: Message edited by: Ryan McGuire ]