title: Running my own version of WordCount.java in Hadoop-2.6.0
body: <p>I am trying to create my own version of wordcount and execute it. For that, I am trying to create the wordcount.jar by executing the following command (as described here <a href="http://cs.smith.edu/dftwiki/index.php/Hadoop_Tutorial_1_--_Running_WordCount" rel="nofollow">http://cs.smith.edu/dftwiki/index.php/Hadoop_Tutorial_1_--_Running_WordCount</a> for previous releases than Hadoop-2.*):</p>
  
  <pre><code>javac -classpath /usr/local/hadoop-2.6.0/share/hadoop/common/*:/usr/local/hadoop-2.6.0/share/hadoop/mapreduce/* -d wordcount_classes/ WordCount.java
  jar -cvf wordcount.jar -C wordcount_classes/ .
  </code></pre>
  
  <p>The problem is that I get errors in the first command when trying to compile the wordcount class. In the first command I try to include all the jars that exist in the common and mapreduce directories, because I don't find any jar that has the name "hadoop-0.19.2-core.jar" as described in tutorials I found in the internet for the hadoop-0.*</p>
  
  <pre><code> javac -classpath /home/hadoop/hadoop/hadoop-0.19.2-core.jar -d wordcount_classes WordCount.java 
  </code></pre>
  
  <p>When I execute the given wordcount as follows, it works perfect, but I can't compile my own version:</p>
  
  <pre><code> hadoop jar /usr/local/hadoop-2.6.0/share/hadoop/mapreduce/hadoop-*-examples-2.6.0.jar wordcount input output
  </code></pre>
  
  <p>I've searched in the internet but I find most of tutorials are for Hadoop-1.* which is different from the 2.6.0 version which does not contain any java source file such as the wordcount.java I need, and also has a completely different structure. Hence, I was obliged to download the wordcount.java file separately from <a href="https://github.com/apache/hadoop-common/blob/trunk/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/main/java/org/apache/hadoop/examples/WordCount.java" rel="nofollow">https://github.com/apache/hadoop-common/blob/trunk/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/main/java/org/apache/hadoop/examples/WordCount.java</a>
  and copy the WordCount.java in the current directory where I execute my commands to create the jar.</p>
  
  <p>I've downloaded Hadoop from this source <a href="http://mirror.its.dal.ca/apache/hadoop/common/hadoop-2.6.0/" rel="nofollow">http://mirror.its.dal.ca/apache/hadoop/common/hadoop-2.6.0/</a></p>
  
  <p>Here is the details of the errors I get:</p>
  
  <pre><code>  /usr/local/hadoop-2.6.0/share/hadoop/common/hadoop-common-2.6.0.jar(org  /apache/hadoop/fs/Path.class): warning: Cannot find annotation method 'value()' in type 'LimitedPrivate': class file for org.apache.hadoop.classification.InterfaceAudience not found
    WordCount.java:54: error: cannot access Options
  String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
                       ^
  class file for org.apache.commons.cli.Options not found
  WordCount.java:68: error: method waitForCompletion in class Job cannot be applied to given types;
  System.exit(job.waitForCompletion() ? 0 : 1);
                 ^
  required: boolean
  found: no arguments
  reason: actual and formal argument lists differ in length
  Note: WordCount.java uses or overrides a deprecated API.
  Note: Recompile with -Xlint:deprecation for details.
  2 errors
  1 warning
  </code></pre>
  
  <p>Here is also the WordCount.java :</p>
  
  <pre><code>//package org.apache.hadoop.examples;
  package org.myorg;
  
  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.output.FileOutputFormat;
  import org.apache.hadoop.util.GenericOptionsParser;
  
  public class WordCount {
  
  public static class TokenizerMapper 
     extends Mapper&lt;Object, Text, Text, IntWritable&gt;{
  
  private final static IntWritable one = new IntWritable(1);
  private Text word = new Text();
  
  public void map(Object key, Text value, Context context
                  ) throws IOException, InterruptedException {
    StringTokenizer itr = new StringTokenizer(value.toString());
    while (itr.hasMoreTokens()) {
      word.set(itr.nextToken());
      context.write(word, one);
     }
   }
  }
  
  public static class IntSumReducer 
     extends Reducer&lt;Text,IntWritable,Text,IntWritable&gt; {
  private IntWritable result = new IntWritable();
  
  public void reduce(Text key, Iterable&lt;IntWritable&gt; values, 
                     Context context
                     ) throws IOException, InterruptedException {
    int sum = 0;
    for (IntWritable val : values) {
      sum += val.get();
    }
    result.set(sum);
    context.write(key, result);
    }
  }
  
  public static void main(String[] args) throws Exception {
  Configuration conf = new Configuration();
  String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
  if (otherArgs.length != 2) {
    System.err.println("Usage: wordcount &lt;in&gt; &lt;out&gt;");
    System.exit(2);
  }
  Job job = new Job(conf, "word count");
  job.setJarByClass(WordCount.class);
  job.setMapperClass(TokenizerMapper.class);
  job.setCombinerClass(IntSumReducer.class);
  job.setReducerClass(IntSumReducer.class);
  job.setOutputKeyClass(Text.class);
  job.setOutputValueClass(IntWritable.class);
  FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
  FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
  System.exit(job.waitForCompletion() ? 0 : 1);
   }
  }
  </code></pre>
  
  <p>Thank you in advance for your help</p>