File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mac OS and the fly likes Java Environment Setup Problem - OS X 10.4.3, Java 1.5.0 - Running from Terminal 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 » Engineering » Mac OS
Bookmark "Java Environment Setup Problem - OS X 10.4.3, Java 1.5.0 - Running from Terminal" Watch "Java Environment Setup Problem - OS X 10.4.3, Java 1.5.0 - Running from Terminal" New topic
Author

Java Environment Setup Problem - OS X 10.4.3, Java 1.5.0 - Running from Terminal

Marcus Peaston
Greenhorn

Joined: Nov 01, 2005
Posts: 1
Hi Guys,

I've been having real problems recently running Java applications from the Terminal that can be summed up with the following error message:

Exception in thread "main" java.lang.NoClassDefFoundError

As best as I can tell, for some reason my CLASSPATH environment variable had become incorrect. Oddly, even running the applications using the command "java -cp . path.to.class.package" didn't work all the time, by which I mean that it would work initially and then I'd start getting the NoClassDefFoundError exception until I restarted the Terminal. Strange, no?

At the present time everything seems to work OK if I run my applications from within Eclipse 3.1 and adding "." to the end of the CLASSPATH environment variable seems to have sorted most problems out. However, I am still getting the NoClassDefFoundError exception when attempting to run an application that makes use of an external JAR. Again, it works fine in Eclipse but it doesn't seem to export the JAR into the output directory despite it having been flagged in the "Build Path > Order and Export" options in Eclipse. Copying the JAR file into the output directory and running Java still results in the exception. Not sure if the above is clear but perhaps the following directory tree will help:

bin
|
|- net
| |
| |-kelmon
| |
| |- MyTestClass.class
|
|- ExternalJar.jar

Running the command "java net.kelmon.MyTestClass" results in the message "Exception in thread "main" java.lang.NoClassDefFoundError: com/externaljar/SomeClass at net.kelmon.MyTestClass.<init>". Given that the JAR file is sat in the current working directory and that the current working directory is specified on the CLASSPATH, shouldn't the classes in the JAR file be automatically available, or am I doing something wrong?

All suggestions are gratefully received,

Regards,

Marcus
Loren Rosen
Ranch Hand

Joined: Feb 12, 2003
Posts: 156
A couple of things that might be going on.

classpaths have elements separated by colons ( the : character). But in the command line example you have
java -cp . path.to.class.package
instead of
java -cp . ath.to.class.package

Second, check the structure of your jar file, using 'jar t'. what often happens is that the class files are there in the jar but path to it inside the jar isn't what it should be.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

By the way, here's a neat GUI for setting environment variables on Mac...

http://www.rubicode.com/Software/RCEnvironment/


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Environment Setup Problem - OS X 10.4.3, Java 1.5.0 - Running from Terminal
 
Similar Threads
NoClassDefFoundError
NoClassDefFoundError
NoClassDefFoundError
NoClassDefFoundError
NoClassDefFoundError