I have used hadoop 0.18.3 previously and shifted to version 0.20.2. I have setup hadoop in a pseudo distributed mode and then tried running the wordcount program available here. I have followed the instructions for compiling and running. But, I got the following errors on running.
java.lang.RuntimeException: java.lang.ClassNotFoundException: WordCount$Map
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:809)
at org.apache.hadoop.mapreduce.JobContext.getMapperClass(JobContext.java:157)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:569)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:305)
at org.apache.hadoop.mapred.Child.main(Child.java:170)
Caused by: java.lang.ClassNotFoundException: WordCount$Map
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:762)
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:807)
I googled it and found that we need to add one line of code to rectify this problem. As the name of my program is WordCount, I have added the following line in the main of my class file.
job.setJarByClass(WordCount.class);
That fixed the error. So dont forget to add that line in your future programs.
Subscribe to:
Post Comments (Atom)
thanks! works for me.
ReplyDeleteIt bothers me that tutorial code is wrong.
How come this happen for Yahoo.
Excellent tip
ReplyDelete