Recently, I encountered an unusual exception while executing a Java program on my Linux system :
I wrote a simple “Hello World” program and compiled it using javac compiler. When I tried executing this “Hello World” program I got this error:
Exception in thread “main” java.lang.NoClassDefFoundError
I diagnosed my system environment variables, checking if they are not set properly :
My Java is installed at :
/usr/local/j2sdk1.4.2_03/
$ echo $JAVA_HOME
/usr/local/j2sdk1.4.2_03
/usr/local/j2sdk1.4.2_03
$ echo $CLASSPATH
/usr/local/j2sdk1.4.2_03/bin
/usr/local/j2sdk1.4.2_03/bin
$ echo $PATH
/usr/local/j2sdk1.4.2_03/bin
/usr/local/j2sdk1.4.2_03/bin
All variables are set correctly but still i was getting this “Exception in thread “main” java.lang.NoClassDefFoundError” error.
Then after lot of struggle I found the problem :
In Redhat systems even though we installed the RPM of Sun’s JRE there is still an OLD version of JAVA binary at /usr/bin.
Solution :
I moved this old version of java binary to :
mv /usr/bin/java /usr/bin/java.old
and created a link to latest version of java binary
ln -s /usr/java/jre1.4.2_03/bin/java /usr/bin/java
Basically, these steps replaced the old version of java with the version of java we are using and finally my “Hello World” program started working.
Comments
Post a Comment