Reputation: 4728
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);
}
}
Upvotes: 0
Views: 215
Reputation: 1502466
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.
Upvotes: 3