写了一个练习的mapreduce程序,参照《hadoop权威指南》第二章,代码见后:NewMaxTemperature.java 成功编译,并将三个class打包成jar,然后调用如下:
hadoop jar NewMaxTemperature.jar NewMaxTemperature /tempData/998218-99999-2008.op /7.txt
运行出错。
问题如下:
总是提示
java.lang.RuntimeException: java.lang.ClassNotFoundException: NewMaxTemperature$NewMaxTemperatureMapper;
但是我已经设置了jar包并且设置了全局变量 HADOOP_CLASSPATH=".:/opt/hadoop/build/classes"
错误信息如下:
11/12/04 20:20:48 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
11/12/04 20:20:48 WARN mapred.JobClient: No job jar file set. User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
11/12/04 20:20:48 INFO input.FileInputFormat: Total input paths to process : 1
11/12/04 20:20:48 INFO mapred.JobClient: Running job: job_201112041508_0034
11/12/04 20:20:49 INFO mapred.JobClient: map 0% reduce 0%
11/12/04 20:21:00 INFO mapred.JobClient: Task Id : attempt_201112041508_0034_m_000000_0, Status : FAILED
java.lang.RuntimeException: java.lang.ClassNotFoundException: NewMaxTemperature$NewMaxTemperatureMapper
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:809)
at org.apache.hadoop.mapreduce.JobContext.getMapperClass(JobContext.java:157)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:569)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:305)
at org.apache.hadoop.mapred.Child.main(Child.java:170)
Caused by: java.lang.ClassNotFoundException: NewMaxTemperature$NewMaxTemperatureMapper
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:762)
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:807)
... 4 more
11/12/04 20:21:06 INFO mapred.JobClient: Task Id : attempt_201112041508_0034_m_000000_1, Status : FAILED
java.lang.RuntimeException: java.lang.ClassNotFoundException: NewMaxTemperature$NewMaxTemperatureMapper
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:809)
at org.apache.hadoop.mapreduce.JobContext.getMapperClass(JobContext.java:157)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:569)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:305)
at org.apache.hadoop.mapred.Child.main(Child.java:170)
Caused by: java.lang.ClassNotFoundException: NewMaxTemperature$NewMaxTemperatureMapper
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:762)
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:807)
... 4 more
11/12/04 20:21:12 INFO mapred.JobClient: Task Id : attempt_201112041508_0034_m_000000_2, Status : FAILED
java.lang.RuntimeException: java.lang.ClassNotFoundException: NewMaxTemperature$NewMaxTemperatureMapper
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:809)
at org.apache.hadoop.mapreduce.JobContext.getMapperClass(JobContext.java:157)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:569)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:305)
at org.apache.hadoop.mapred.Child.main(Child.java:170)
Caused by: java.lang.ClassNotFoundException: NewMaxTemperature$NewMaxTemperatureMapper
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:762)
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:807)
... 4 more
11/12/04 20:21:21 INFO mapred.JobClient: Job complete: job_201112041508_0034
11/12/04 20:21:21 INFO mapred.JobClient: Counters: 3
11/12/04 20:21:21 INFO mapred.JobClient: Job Counters
11/12/04 20:21:21 INFO mapred.JobClient: Launched map tasks=4
11/12/04 20:21:21 INFO mapred.JobClient: Data-local map tasks=4
11/12/04 20:21:21 INFO mapred.JobClient: Failed map tasks=1
=========================================================
代码为:
import java.io.IOException;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class NewMaxTemperature {
static class NewMaxTemperatureMapper
/*[*/extends Mapper/*]*/ {
private static final int MISSING = 9999;
public void map(LongWritable key, Text value, /*[*/Context context/*]*/) throws IOException, /*[*/InterruptedException/*]*/ {
// public void map( LongWritable key , Text value, OutputCollector output, Reporter reporter ) throws IOException {
String line = value.toString();
String year = line.substring(15,18);
float airTemperature;
airTemperature = Float.parseFloat( line.substring( 25,30 ));
context.write( new Text(year),new FloatWritable( airTemperature ) );
}
}
/*
public static class MaxTemperatureReducer extends MapReduceBase
implements Reducer {
public void reduce( Text key,Iterator values, OutputCollector output,Reporter reporter) throws IOException {
*/
static class NewMaxTemperatureReducer
/*[*/extends Reducer/*]*/ {
public void reduce(Text key, /*[*/Iterable/*]*/ values,
/*[*/Context context/*]*/)
throws IOException, /*[*/InterruptedException/*]*/ {
float maxValue = -9999;
for (FloatWritable value : values) {
maxValue = Math.max(maxValue, value.get());
}
/*[*/context.write/*]*/(key, new FloatWritable(maxValue));
}
}
public static void main( String[] args ) throws Exception {
if( args.length != 2) {
System.err.println( "usage: MaxTemperature [i] " );
System.exit( -1 );
}
/*
System.err.println( "usage: 1" );
JobConf conf = new JobConf( MaxTemperature.class );
System.err.println( "usage: 2" );
conf.setJobName("Max Temperature");
FileInputFormat.addInputPath( conf,new Path(args[0]) );
FileOutputFormat.setOutputPath(conf,new Path(args[1]));
conf.setMapperClass( MaxTemperatureMapper.class );
conf.setReducerClass( MaxTemperatureReducer.class);
// conf.setOutputkeyClass( Text.class );
conf.setOutputKeyClass( Text.class );
conf.setOutputValueClass( FloatWritable.class );
JobClient.runJob( conf );
*/
/*[*/Job job = new Job();
job.setJarByClass(NewMaxTemperature.class);/*]*/
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.setMapperClass(NewMaxTemperatureMapper.class);
job.setReducerClass(NewMaxTemperatureReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
System.exit( job.waitForCompletion(true) ? 0 : 1 );
}
}
|
|