Hadoop Mapreduce: Class Not Found Exception

0 votes

I am trying to run a wordcount job in hadoop. This is the code I am running

 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, Iterable<IntWritable> values, Context context) 
      throws IOException, InterruptedException {
        int sum = 0;
        for (IntWritable val : values) {
            sum += val.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);
    job.setJarByClass(WordCount.class);
 }
}

This is the command i use to run

   jeet@jeet-Vostro-2520:~/Downloads$ hadoop jar wordcount.jar org.gamma.WordCount /user/jeet/getty/gettysburg.txt /user/jeet/getty/out

The error:

 at org.apache.hadoop.mapred.Child.main(Child.java:249) Caused by: java.lang.ClassNotFoundException: org.gamma.WordCount$Map  14/01/27 13:16:26 INFO mapred.JobClient: Job complete: job_201401271247_0001 14/01/27 13:16:26 INFO mapred.JobClient: Counters: 7 14/01/27 13:16:26 INFO mapred.JobClient: Job Counters 14/01/27 13:16:26 INFO mapred.JobClient: SLOTS_MILLIS_MAPS=20953 14/01/27 13:16:26 INFO mapred.JobClient: Total time spent by all reduces waiting after reserving slots (ms)=0 14/01/27 13:16:26 INFO mapred.JobClient: Total time spent by all maps waiting after reserving slots (ms)=0 14/01/27 13:16:26 INFO mapred.JobClient: Launched map tasks=4 14/01/27 13:16:26 INFO mapred.JobClient: Data-local map tasks=4 14/01/27 13:16:26 INFO mapred.JobClient: SLOTS_MILLIS_REDUCES=0 14/01/27 13:16:26 INFO mapred.JobClient: Failed map tasks=1  

Somebody please help

Oct 29, 2018 in Big Data Hadoop by digger
• 27,620 points
303 views

1 answer to this question.

0 votes

Try adding this

Job job = new Job(conf, "wordcount");
job.setJarByClass(WordCount.class);
answered Oct 29, 2018 by Omkar
• 67,120 points

Related Questions In Big Data Hadoop

0 votes
1 answer

Class not found exception when I am running my Word Count Program jar file

You have forgotten to include the package name ...READ MORE

answered Jan 18 in Big Data Hadoop by Omkar
• 67,120 points
23 views
+1 vote
1 answer
0 votes
1 answer

hadoop: command not found

The reason you are getting hadoop as ...READ MORE

answered Mar 27, 2018 in Big Data Hadoop by kurt_cobain
• 9,240 points
2,211 views
0 votes
1 answer

Hadoop Oozie: E0902: Exception occured: [User: oozie is not allowed to impersonate oozie]

Seems like your version of Hadoop does ...READ MORE

answered Nov 12, 2018 in Big Data Hadoop by Omkar
• 67,120 points
75 views
0 votes
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,030 points
2,026 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,030 points
188 views
0 votes
10 answers

hadoop fs -put command?

copy command can be used to copy files ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Sujay
10,236 views
0 votes
1 answer

Hadoop dfs -ls command?

In your case there is no difference ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by kurt_cobain
• 9,240 points
751 views
0 votes
1 answer

PIG - Found interface org.apache.hadoop.mapreduce.JobContext, but class was expected

Yes, it is a compatibility issue. in Hadoop ...READ MORE

answered Oct 10, 2018 in Big Data Hadoop by Omkar
• 67,120 points
56 views
0 votes
1 answer

Hadoop Mapreduce: Error: Could not find or load main class com.sun.tools.javac.Main

You have to add HADOOP_CLASSPATH environment parameter: export ...READ MORE

answered Oct 30, 2018 in Big Data Hadoop by Omkar
• 67,120 points
256 views