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 Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in thread "main"" Watch "Exception in thread "main"" New topic
Author

Exception in thread "main"

Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
While am trying to run a simple java program in UNIX machine am getting
"Exception in thread "main" java.lang.NoClassDefFoundError"

Even after setting
export JAVA_HOME=/opt/java1.5/bin
export PATH=$PATH:/opt/java1.5/bin

Please assist Me.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
It means you have no .class file matching the name in your current directory.
Go and find the .java file for the class with the main method it, and read its package declaration. If there is no package declaration, then you need to navigate to whichever directory contains that .java file, and check there is a corresponding .class file with the ls command.

If there is a package declaration, you ought not to be in the same directory as the .class file. If the .java file starts like thisyou should be in a directory which contains the directory called "com"; "com" contains "foo" and "foo" contains "bar" and the "bar" directory contains MyMainClass.class. At least it will if it has compiled correctly.
You invoke the main method by writing

java com.foo.bar.MyMainClass args0 args1

Try that, and make sure all the .class files are in the right locations.

That error has nothing to do with the PATH variable.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
More details here.
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Working Fine !!!

Thanks a Lot

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
Originally posted by Meet Gaurav:
Working Fine !!!

Thanks a Lot



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread "main"