Class not found exception in wordcount program in mapreduce

+1 vote
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import java.io.IOException;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.io.*;
public class WordCount
{
    public static void main(String []args) throws Exception
    {
        if(args.length!=2)
        {
            System.err.println("Invalid command");
            System.exit(0);
        }
        Configuration conf = new Configuration();
        Job job = new Job(conf, "WordCount");
        job.setJarByClass(WordCount.class);
        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));
        job.setMapperClass(WordMapper.class);
        job.setReducerClass(WordReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        job.waitForCompletion(true);
    }

class WordMapper extends Mapper<LongWritable, Text, Text, IntWritable>
    {
        public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException
        {
            String line = value.toString();
            String[] word = line.split(" ");
            for(String i : word)
            {
                if(i.length()>0)
                {
                    context.write(new Text(i), new IntWritable(1));
                }
            }
        }
    }
    class WordReducer extends Reducer<Text, IntWritable, Text, IntWritable>
    {
        public void reduce(Text key, Iterable<IntWritable> value, Context context) throws IOException, InterruptedException
        {
            int count =0;
            for(IntWritable i: value)
            {
                count = count+ i.get();
            }
            context.write(key, new IntWritable(count));
        }
    }
}
Oct 3 in Big Data Hadoop by Tarun
• 160 points

edited Oct 3 by Omkar 99 views
What command did you use to run the code?
hadoop jar jarname packagename.classname input output

Try including the full package name and see if it works:

hadoop jar wordcount.jar com.something.WordCount input output

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Big Data Hadoop

0 votes
1 answer

Hadoop Mapreduce: Class Not Found Exception

Try adding this Job job = new Job(conf, ...READ MORE

answered Oct 29, 2018 in Big Data Hadoop by Omkar
• 68,480 points
599 views
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
• 68,480 points
57 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
• 68,480 points
114 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
• 68,480 points
543 views
0 votes
1 answer

Hadoop Hive: message:Version information not found in metastore. Unable to instantiate

These are the necessary tables required for metastore that are ...READ MORE

answered Nov 12, 2018 in Big Data Hadoop by Omkar
• 68,480 points
642 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,800 points
3,582 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,800 points
455 views
+1 vote
11 answers

hadoop fs -put command?

put syntax: put <localSrc> <dest> copy syntax: copyFr ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Aditya
18,448 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,280 points
1,334 views