Thursday, January 06, 2005

Make sure that CLASSPATH is correct

I had an issue with a java class today that I was trying to execute from the command line.  I kept getting the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: Example
After doing a little research, I found that my CLASSPATH variable was set to c:\junit3.8.1\junit.jar which was not allowing the virtual machine to properly find the binaries it needed to execute the class.  After clobbering the CLASSPATH variable (“set CLASSPATH=“), everything worked as expected.

Update
Someone that I work with gave me a good tip today that I did not know regarding Java and how it parses the CLASSPATH variable.  Make sure that you have a dot in the path declaration at the end.  In other words, in my case, the CLASSPATH would be something like this:

CLASSPATH=.;c:\junit\junit3.8.1\junit.jar
For those of you who can't quite see it, that is a period at the beginning of the CLASSPATH declaration.  This tells Java to use the current directory when searching for classes and JAR files.

Technorati Tags: ,