我一直在寻找解决此问题的方法,但无济于事。我有三个 scala 类:MaxTemperatureMapper
、MaxTemperatureReducer
和MaxTemperatureDriver
(参见下面的实现)。之前线程中的一些人删除了job.setJar()
Main class( MaxTemperatureDriver
) 中的方法以使 hadoop 作业运行。那对我不起作用。运行时,我继续收到以下堆栈跟踪:
hadoop com.koadr.hadoop.MaxTemperatureDriver micro/sample.txt output
hadoop jar target/classes/koadr-hadoop-1.0-SNAPSHOT.jar com.koadr.hadoop.MaxTemperatureDriver micro/sample.txt output
:
.
java.lang.RuntimeException: java.lang.ClassNotFoundException: Class com.koadr.hadoop.MaxTemperatureMapper not found
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:1587)
at org.apache.hadoop.mapreduce.task.JobContextImpl.getMapperClass(JobContextImpl.java:191)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:631)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:330)
at org.apache.hadoop.mapred.Child$4.run(Child.java:268)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1408)
at org.apache.hadoop.mapred.Child.main(Child.java:262)
Caused by: java.lang.ClassNotFoundException: Class com.koadr.hadoop.MaxTemperatureMapper not found
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:1493)
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:1585)
... 8 more
我在 intellij IDE 中工作,并使用 maven 进行依赖、编译等。我在命令行上运行上述 hadoop 命令。有人可以解释我哪里出错了吗?为什么找不到 Mapper 类?
最大温度映射器:
class MaxTemperatureMapper extends Mapper[Object, Text, Text, IntWritable] {
private def missing( temp : String) : Boolean = {
temp.equals("+9999")
}
override def map(key: Object, value: Text, context:Mapper[Object,Text,Text,IntWritable]#Context ) = {
val line : String = value.toString
val year : String = line.substring(15, 19)
val temp : String = line.substring(87,92)
if (!missing(temp)) {
val airTemp : Int = Integer.parseInt(line.substring(87,92))
context.write(new Text(year), new IntWritable(airTemp))
}
}
}
MaxTemperatureReducer:
class MaxTemperatureReducer extends Reducer[Text, IntWritable, Text, IntWritable] {
override
def reduce (key: Text, values: java.lang.Iterable[IntWritable], context:Reducer[Text, IntWritable, Text, IntWritable]#Context) = {
def maxVal(values : List[IntWritable], cMaxV : Int) : Int = {
if (values.isEmpty) cMaxV
else maxVal(values.tail,math.max(cMaxV, values.head.get()))
}
context write(new Text(key), new IntWritable(maxVal(values.toList,Integer.MIN_VALUE)) )
}
}
最高温度驱动程序:
class MaxTemperatureDriver extends Configured with Tool {
override
def run(args : Array[String]) : Int = {
if (args.length != 2) {
System.err.printf("Usage: %s [generic options] <input> <output>\n", getClass.getSimpleName)
ToolRunner.printGenericCommandUsage(System.err)
-1
}
val job : Job = Job.getInstance(getConf, "Max Temperature")
job.setJarByClass(getClass)
FileInputFormat.addInputPath(job, new Path(args(0)))
FileOutputFormat.setOutputPath(job, new Path(args(1)))
job.setMapperClass(classOf[MaxTemperatureMapper])
job.setCombinerClass(classOf[MaxTemperatureReducer])
job.setReducerClass(classOf[MaxTemperatureReducer])
job.setOutputKeyClass(classOf[Text])
job.setOutputValueClass(classOf[IntWritable])
if (job.waitForCompletion(true)) 0 else 1
}
}
object MaxTemperatureDriver {
def main(args : Array[String]) = {
val exitCode : Int = ToolRunner.run(new MaxTemperatureDriver, args)
System.exit(exitCode)
}
}