Domanda

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:

[root@dev 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 ?

È stato utile?

Soluzione

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

[root@dev 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

[root@dev 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.

Altri suggerimenti

Try removing the throws Exception statement.

You don't need to declare a throwing statement in the main function, since it's the entry point and the last method on the calling stack. It does not need to report to anyone.

I don't know too much about JVM but I'm guessing it's trying to look for a specific main signature, and adding that throws Exception, makes the JVM to not recognize the main method.

i think the syntax should be like

hadoop jar target/MapReduce-0.0.1-SNAPSHOT.jar com.hadoop.bi.MapReduce.MaxTemperature sample.txt /out
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top