我在Yarn集群上使用新的MapReduce Api。我需要从两个不同的目录中读取两种不同格式的文件。为此,我决定使用MultipleInputs来指定两个映射器类。以下是我的工作司机
Job job = new Job(new Configuration(), "Daily Report");
job.setJarByClass(MyDailyJob.class);
MultipleInputs.addInputPath(job, new Path(args[0]), TextInputFormat.class, Record1ParsingMapper.class);
MultipleInputs.addInputPath(job, new Path(args[1]), TextInputFormat.class, Record2ParsingMapper.class);
FileOutputFormat.setOutputPath(job, new Path(args[2]));
job.setReducerClass(ReportParsingReducer.class);
job.setNumReduceTasks(10);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(NullWritable.class);
return (job.waitForCompletion(true) ? 0 : 1);
我的Mappers有以下定义: 公共类Record1ParsingMapper扩展了Mapper
当我运行这份工作时,我得到以下异常:
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/parser/ParseException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at org.apache.hadoop.conf.Configuration.getClassByNameOrNull(Configuration.java:1986)
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:1951)
at org.apache.hadoop.mapreduce.lib.input.MultipleInputs.getMapperTypeMap(MultipleInputs.java:141)
at org.apache.hadoop.mapreduce.lib.input.DelegatingInputFormat.getSplits(DelegatingInputFormat.java:60)
at org.apache.hadoop.mapreduce.JobSubmitter.writeNewSplits(JobSubmitter.java:498)
at org.apache.hadoop.mapreduce.JobSubmitter.writeSplits(JobSubmitter.java:515)
at org.apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobSubmitter.java:399)
at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1295)
at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1292)
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:1614)
at org.apache.hadoop.mapreduce.Job.submit(Job.java:1292)
at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:1313)
at main.java.com.adnear.mr.jobs.MyDailyJob.run(MyDailyJob.java:70)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:84)
at main.java.com.adnear.mr.jobs.MyDailyJob.main(MyDailyJob.java:226)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
Caused by: java.lang.ClassNotFoundException: org.json.simple.parser.ParseException\
看起来它在以下语句的Configuration类中的getClassByName()方法内失败了。 clazz = Class.forName(name,true,classLoader);
我正确指定了Mapper类的路径。有人可以解释一下造成这个类加载异常的原因吗?
谢谢, 开发
答案 0 :(得分:0)
Caused by: java.lang.ClassNotFoundException: org.json.simple.parser.ParseException
错误消息明确指出类路径中缺少某些类。此类是运行时执行json-simple-1.1.1.jar
所需的Job
jar文件的一部分。因此,在类路径中添加此jar文件以成功运行Job。
您可以从HERE获取jar文件
希望它有所帮助!