NoClassDefFoundError Error in Hadoop
11,770
You need to create a jar out of the java code like given here:
$ mkdir my_classes
$ javac -classpath $HADOOP_HOME/hadoop-$HADOOP_VERSION-core.jar -d my_classes <name of the main class>
$ jar -cvf <name of the jar> -C my_classes .
Run the jar this way:
$HADOOP_HOME/bin/hadoop jar <name of the jar> <name of the main class> <arguments to the program>
See the documentation page of hadoop for the description of jar command.
Comments
-
SLearner almost 2 years
So after going through many posts on SO and revising some java basics, I still get this error
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/io/Writable at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2451) at java.lang.Class.getMethod0(Class.java:2694) at java.lang.Class.getMethod(Class.java:1622) at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
I know the difference between
java.lang.NoClassDefFoundError
andClassNotFoundException
in Java, and have looked through what usually causes it. In a nutshell, it is because some class is unavailable to the program during Run Time but is available during Compile time. Hence I get no compile time errors.I have added two classpaths, one to
commons-logging-1.1.3.jar
and the other to thehadoop-core.*jar
. I am pretty confident that the classpaths are correct.Here are the imports in my Program
import java.io.*; import org.apache.hadoop.io.SequenceFile; import org.apache.hadoop.io.SequenceFile.*; import org.apache.hadoop.io.SequenceFile.Writer; import org.apache.hadoop.io.*; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.io.Writable; import org.apache.hadoop.fs.Path; import org.apache.hadoop.conf.*; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.*;