이 문제에 대한 해결책을 찾지 않았습니다. 세 개의 스칼라 클래스가 있습니다 : MaxTemperatureMapper
, MaxTemperatureReducer
및 MaxTemperatureDriver
(아래 구현 참조). 이전 스레드의 일부 사용자는 메인 클래스 (MaxTemperatureDriver
)의 job.setJar()
메소드를 제거하여 hadoop 작업을 실행했습니다. 그건 나를 위해 작동하지 않았다. 중 하나를 실행할 때 나는 다음과 같은 스택 트레이스가 계속 : hadoop com.koadr.hadoop.MaxTemperatureDriver micro/sample.txt output
Hadoop 작업이 java.lang.ClassNotFoundException에서 실패합니다.
hadoop jar target/classes/koadr-hadoop-1.0-SNAPSHOT.jar com.koadr.hadoop.MaxTemperatureDriver micro/sample.txt output
:
. 나는하게 IntelliJ IDE하고 있어요 등 내가 명령 줄에 상기 하둡 명령을 실행하고, 컴파일, 종속성을 받는다는 사용하고
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
. 누군가 내가 잘못 가고 있다고 설명 할 수 있습니까? Mapper 클래스가없는 이유는 무엇입니까?
MaxTemperatureMapper :
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)))
}
}
MaxTemperatureDriver : 당신은에 모두 HADOOP_CLASSPATH
및 -libjars
에서 같은 작업을 제출에 종속성을 추가 할 필요가
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)
}
}
hadoop 클래스 경로를 설정 했습니까? "hadoop classpath"를 실행하여 파일이 무엇인지 확인하고 .class 파일이 해당 디렉토리 중 하나에 있는지 확인하십시오. – Heptic
haddop 클래스 경로에는 MaxTemperatureDriver.class, MaxTemperatureDriver $ .class, MaxTemperatureMapper.class 및 MaxTemperatureReducer.class가 중첩 된 target/classes /가 포함되어 있습니다. – user2468434
'jar tvf target/classes/koadr-hadoop-1.0-SNAPSHOT .jar' 그래서 우리는 항아리에 묶여있는 클래스를 볼 수 있습니다. –