Exception in thread “main” java.lang.ClassNotFoundException:MaxTemperature

I am running a single node hadoop, after trying to run a mapreduce application I got this exception:

Exception in thread "main" java.lang.ClassNotFoundException: src.main.java.com.hadoop.bi.MapReduce.MaxTemperature 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:201)

and what I ran in terminal was:

[[email protected] MapReduce]# hadoop jar target/MapReduce-0.0.1-SNAPSHOT.jar src/main/java/com/hadoop/bi/MapReduce/MaxTemperature sample.txt /out

and here is my MaxTempreture class content:

    package com.hadoop.bi.MapReduce;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class MaxTemperature {

  public static void main(String[] args) throws Exception {
    if (args.length != 2) {
      System.err.println("Usage: MaxTemperature <input path> <output path>");
      System.exit(-1);
    }
    Configuration conf = new Configuration();
    Job job = new Job(conf, "MaxTemperature");  
    job.setJarByClass(MaxTemperature.class);


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

    job.setMapperClass(MaxTemperatureMapper.class);
    job.setReducerClass(MaxTemperatureReducer.class);

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

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

I have followed most of similar problems on the internet but I haven’t find the solution yet. Anyone know what the problem is and how it could be solved ?

Answer

Your command line to execute the said class is not correct. You are giving path with folders included. instead you shall give fully qualified class name

[[email protected] MapReduce]# hadoop jar target/MapReduce-0.0.1-SNAPSHOT.jar src/main/java/com/hadoop/bi/MapReduce/MaxTemperature sample.txt /out

should be changed to

[[email protected] MapReduce]# hadoop jar target/MapReduce-0.0.1-SNAPSHOT.jar com/hadoop/bi/MapReduce/MaxTemperature sample.txt /out

as per your package heirarchy.

Hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *