我運行一個單一節點的Hadoop,試圖運行映射縮減應用程序,我得到這個異常後:異常線程「main」拋出java.lang.ClassNotFoundException:MaxTemperature
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)
和我在跑終端是:
[[email protected] MapReduce]# hadoop jar target/MapReduce-0.0.1-SNAPSHOT.jar src/main/java/com/hadoop/bi/MapReduce/MaxTemperature sample.txt /out
,這裏是我的MaxTempreture類內容:
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);
}
}
我在網上跟隨了大多數類似的問題,但我還沒有找到解決方案。任何人都知道問題是什麼以及如何解決?
你編譯在此之前的Java源文件? –
我用maven構建並創建了一個jar文件 – sina
你必須確保你的jar包含了你所寫的任何和所有類/庫:我通常使用maven插件(如shaded-plugin)來執行此操作,以便爲你提供an-in -one jar:打開你的jar並看看它是否真的擁有你期望的類。 – davek