0

I have created the simple 'WordCount.java' file for implementing a simple hadoop program and upon compilation, it does not create a .jar file. The files created at WordCount.class, WordCount$Map.class, and WordCount$Reduce.class. I looked in the WordCount.java file and it does include a public static void main(String[] args) routine, so it should create a .jar file, right?

This is my first venture into Java in quite a while, so it could easily be a mistake in how Java compiles, but given the following code, shouldn't it give me a .jar file upon proper compilation?

package org.myorg;

import java.io.IOException;
import java.util.*;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

public class WordCount {

  public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> {
  private final static IntWritable one = new IntWritable(1);
  private Text word = new Text();

  public void map(LongWritable key, Text value, Context context) throws IOException,         
             InterruptedException {
     String line = value.toString();
     StringTokenizer tokenizer = new StringTokenizer(line);
     while (tokenizer.hasMoreTokens()) {
         word.set(tokenizer.nextToken());
         context.write(word, one);
     }
  }
}

 public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {

 public void reduce(Text key, Iterator<IntWritable> values, Context context)
         throws IOException, InterruptedException {
     int sum = 0;
     while (values.hasNext()) {
         sum += values.next().get();
     }
     context.write(key, new IntWritable(sum));
  }
}

public static void main(String[] args) throws Exception {
  Configuration conf = new Configuration();
  Job job = new Job(conf, "wordcount");

  job.setOutputKeyClass(Text.class);
  job.setOutputValueClass(IntWritable.class);

  job.setMapperClass(Map.class);
  job.setReducerClass(Reduce.class);

  job.setInputFormatClass(TextInputFormat.class);
  job.setOutputFormatClass(TextOutputFormat.class);

  FileInputFormat.addInputPath(job, new Path(args[0]));
  FileOutputFormat.setOutputPath(job, new Path(args[1]));

  job.waitForCompletion(true);
  }

}
blackSmith
  • 3,054
  • 1
  • 20
  • 37
drjrm3
  • 4,474
  • 10
  • 53
  • 91
  • possible duplicate of [How to make an executable jar file?](http://stackoverflow.com/questions/5258159/how-to-make-an-executable-jar-file) – khelwood Nov 03 '14 at 22:14

1 Answers1

3

I have created the simple 'WordCount.java' file for implementing a simple hadoop program and upon compilation, it does not create a .jar file.

No, it wouldn't. The output of compilation of .java files (with javac) is a collection of .class files.

You then use the jar tool creates a jar file containing those class files and whatever other resources you need.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • He is using a console perhaps. – blackSmith Nov 04 '14 at 06:07
  • @blackSmith: I don't see the relevance of that comment. – Jon Skeet Nov 04 '14 at 07:08
  • If he's accustomed to an IDE, things would've been simpler I guess. Eg: in eclipse compilation is auto, it's a bit easier to create a jar than finding the .class files. I myself is a bit doubtful over my previous comment's relevance :) – blackSmith Nov 04 '14 at 07:21