title: java.lang.NoClassDefFoundError in Hadoop Basics' MapReduce Program
body: <p>I'm trying Hadoop's Basic MapReduce Program whose tutorial is on <a href="http://java.dzone.com/articles/hadoop-basics-creating" rel="noreferrer">http://java.dzone.com/articles/hadoop-basics-creating</a></p>
  
  <p>The Full code of the class is(the code is present on net on above url)</p>
  
  <pre><code>import java.io.IOException;
  import java.util.StringTokenizer;
  import org.apache.hadoop.conf.Configuration;
  import org.apache.hadoop.fs.Path;
  import org.apache.hadoop.io.IntWritable;
  import org.apache.hadoop.io.Text;
  import org.apache.hadoop.mapreduce.Job;
  import org.apache.hadoop.mapreduce.Mapper;
  import org.apache.hadoop.mapreduce.Reducer;
  import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  import org.apache.hadoop.mapreduce.lib.input.KeyValueTextInputFormat;
  import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  import org.apache.hadoop.util.GenericOptionsParser;
  
  public class Dictionary {
  public static class WordMapper extends Mapper&lt;Text, Text, Text, Text&gt; {
      private Text word = new Text();
  
      public void map(Text key, Text value, Context context) throws IOException, InterruptedException {
          StringTokenizer itr = new StringTokenizer(value.toString(), ",");
          while (itr.hasMoreTokens()) {
              word.set(itr.nextToken());
              context.write(key, word);
          }
      }
  }
  
  public static class AllTranslationsReducer extends Reducer&lt;Text, Text, Text, Text&gt; {
      private Text result = new Text();
  
      public void reduce(Text key, Iterable&lt;Text&gt; values, Context context) throws IOException, InterruptedException {
          String translations = "";
          for (Text val : values) {
              translations += "|" + val.toString();
          }
          result.set(translations);
          context.write(key, result);
      }
  }
  
  public static void main(String[] args) throws Exception {
      System.out.println("welcome to Java 1");
      Configuration conf = new Configuration();
      System.out.println("welcome to Java 2");
      Job job = new Job(conf, "dictionary");
      job.setJarByClass(Dictionary.class);
      job.setMapperClass(WordMapper.class);
      job.setReducerClass(AllTranslationsReducer.class);
      job.setOutputKeyClass(Text.class);
      job.setOutputValueClass(Text.class);
      job.setInputFormatClass(KeyValueTextInputFormat.class);
      FileInputFormat.addInputPath(job, new Path("/tmp/hadoop-cscarioni/dfs/name/file"));
      FileOutputFormat.setOutputPath(job, new Path("output"));
      System.exit(job.waitForCompletion(true) ? 0 : 1);
  }
  }
  </code></pre>
  
  <p>But after running in eclipse; I'm getting the error,</p>
  
  <pre><code>welcome to Java 1
  Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
  at org.apache.hadoop.conf.Configuration.&lt;clinit&gt;(Configuration.java:73)
  at Dictionary.main(Dictionary.java:43)
  Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
  at java.net.URLClassLoader$1.run(Unknown Source)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  ... 2 more
  </code></pre>