0
votes

while executing the command

hadoop jar /home/edureka/Desktop/invertedindex.jar hdfs:/hdfs/inverted  hdfs:/hdfs/invertedout

I'm getting the below error
could anyone help me with the code fix

Exception in thread "main" java.lang.ClassNotFoundException: hdfs:.hdfs.inverted 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:270) at org.apache.hadoop.util.RunJar.main(RunJar.java:205)

I tried with all the prerequisites but still facing the issue.enter code here

Below is the code:

import java.io.IOException;
import java.util.HashMap;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.mapreduce.Reducer;

public class InvertedIndex {

    public static class Map extends Mapper<LongWritable,Text,Text,Text> {


        @Override
        public void map(LongWritable key, Text value, Context context)
        throws IOException,InterruptedException
        {   

            String fileName = ((FileSplit) context.getInputSplit()).getPath().getName();
            String line=value.toString();
            String words[]=line.split(" ");
            for(String s:words){
                context.write(new Text(s), new Text(fileName));
            }


        }
    }

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



      @Override
      public void reduce(Text key, Iterable<Text> values, Context context)
        throws IOException, InterruptedException {
         HashMap m=new HashMap();
         int count=0;
          for(Text t:values){
              String str=t.toString();
              if(m!=null &&m.get(str)!=null){
                  count=(int)m.get(str);
                  m.put(str, ++count);
              }else{`enter code here`
                  m.put(str, 1);    
              }
          }
          context.write(key, new Text(m.toString()));
        }
    }


    public static void main(String[] args) throws Exception { 

        Configuration conf= new Configuration();

        Job job = new Job(conf,"UseCase1");


        //Defining the output value class for the mapper
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(Text.class);
        job.setJarByClass(InvertedIndex.class);
        job.setMapperClass(Map.class);
        job.setReducerClass(Reduce.class);

        //Defining the output value class for the mapper
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);
        job.setInputFormatClass(TextInputFormat.class);
        job.setOutputFormatClass(TextOutputFormat.class);

        Path outputPath = new Path(args[1]);

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

            //deleting the output path automatically from hdfs so that we don't have delete it explicitly

        outputPath.getFileSystem(conf).delete(outputPath);

            //exiting the job only if the flag value becomes false

        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}
2

2 Answers

0
votes

You need to pass Main class in the hadoop jar command as mentioned in the documentation.

Your command

hadoop jar /home/edureka/Desktop/invertedindex.jar hdfs:/hdfs/inverted hdfs:/hdfs/invertedout

should be

hadoop jar /home/edureka/Desktop/invertedindex.jar InvertedIndex hdfs:/hdfs/inverted hdfs:/hdfs/invertedout

Also

job.setJarByClass(InvertedIndex.class);

should be

job.setJarByClass(InvertedIndex);

instead.

I just had a similar discussion here.

0
votes

hadoop command should know which class to execute which is pass right after jar argument:

Usage: hadoop jar <jar> [mainClass] args... - see manual

so you should run jar as:

hadoop jar /home/edureka/Desktop/invertedindex.jar InvertedIndex hdfs:/hdfs/inverted  hdfs:/hdfs/invertedout

job configuration looks good. Don't make any changes to job.setJarbyClass: see Class-Job