2

My program in hadoop 2.7 of wordcount gives error on terminal on running even when it doesn't shows any error in eclipse .

hadoop jar WordCount.jar WordCount user/amandeep/file.txt wordcountoutput

Error shown is below :-

Exception in thread "main" java.lang.ClassNotFoundException: WordCount
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:274)
at org.apache.hadoop.util.RunJar.run(RunJar.java:214)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)

My Wordcount program is -

package hadoop_first;

import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

public class WordCount extends Configured implements Tool{

    @Override
    public int run(String[] args) throws Exception {
        if(args.length<2){
            System.out.println("Give directory properly");
            return -1;
        }
        JobConf conf = new JobConf(WordCount.class);
        conf.setJarByClass(WordCount.class);
        FileInputFormat.setInputPaths(conf,new Path(args[0]));
        FileOutputFormat.setOutputPath(conf,new Path(args[1]));
        conf.setMapperClass(WordCountMapper.class);
        conf.setReducerClass(WordReducer.class);
        conf.setMapOutputKeyClass(Text.class);
        conf.setMapOutputValueClass(IntWritable.class);

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

        JobClient.runJob(conf);
        return 0;
    }
    public static void main(String args[]){
        try{
            int exitCode=ToolRunner.run(new WordCount(),args);
            System.exit(exitCode);
        }
        catch(Exception e){
            System.out.println("Error");
        }
    }
} 

1 Answer 1

2

Solved the problem by adding package name in command typed at terminal

hadoop jar WordCount.jar hadoop_first.WordCount file.txt wordcountoutput 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.