File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Installation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Installation" Watch "Installation" New topic
Author

Installation

Vallabhaneni Suresh Kumar
Ranch Hand

Joined: Mar 01, 2004
Posts: 68
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.

Thank You
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 988
    
    1
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Installation
 
Similar Threads
Jar file problems
Question re: Eclipses class wizard
not able to run my first java program
to make an icon for application.
not able to run my first java program