Sunday, July 5, 2009

Reason for java.lang.ClassNotFoundException

For documents on this: Click here


This problem occurs if the java class is not available in the class path. Or if the jar file containging this class is not placed in the class path. If we get this error, we have to be make sure that the class name for which the exception is occurred, is there in the class path.
The follwing is the command to set the classs path:
In windows:

c:\> SET CLASSPATH=%CLASSPATH%; nameoftheJARfile or nameoftheJAVAclass

In Linux:

$ export CLASSPATH=%CLASSPATH%; nameoftheJARfile or nameoftheJAVAclass

Note on Java

1) While comparing two strings, equals() we should use. Never use == / !=.