hadoop ERROR ON WORDCOUNT PROGRAM

时间:2017-01-17 16:59:39

标签: hadoop mapreduce

 public static void main(String[] args) throws Exception 
 {
    Configuration conf = new Configuration();
    conf.addResource(new Path("/usr/local/hadoop/etc/hadoop/core-site.xml"));
    conf.addResource(new Path("/usr/local/hadoop/etc/hadoop/hdfs-site.xml"));
    Job job = new Job();
    //job.setJarByClass(WordCount.class);
    job.setJobName("WordCounter");

    job.setJarByClass(WordCount.class);
    job.setMapperClass(TokenizerMapper.class);
    job.setCombinerClass(IntSumReducer.class);
    job.setReducerClass(IntSumReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    FileInputFormat.addInputPath(job, new Path("/home/pramukh/eclipse/eclipseproj/hadoop/input/input.txt"));
    FileOutputFormat.setOutputPath(job, new Path("/home/pramukh/eclipse/eclipseproj/hadoop/output.txt"));
//System.exit(0);
    System.exit(job.waitForCompletion(true) ? 0 : 1);
  }

这是我的java hadoop wordcount示例,它给出了以下错误:

  

线程“main”中的异常java.lang.NoClassDefFoundError:   java.lang.Class.forName0上的org / apache / avro / io / DatumReader(Native   方法)在java.lang.Class.forName(Class.java:348)at   org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:1074)     在   org.apache.hadoop.io.serializer.SerializationFactory.add(SerializationFactory.java:69)     在   org.apache.hadoop.io.serializer.SerializationFactory。(SerializationFactory.java:62)     在   org.apache.hadoop.mapreduce.split.JobSplitWriter.writeNewSplits(JobSplitWriter.java:117)     在   org.apache.hadoop.mapreduce.split.JobSplitWriter.createSplitFiles(JobSplitWriter.java:74)     在   org.apache.hadoop.mapred.JobClient.writeNewSplits(JobClient.java:1030)     在   org.apache.hadoop.mapred.JobClient.writeSplits(JobClient.java:1041)     在org.apache.hadoop.mapred.JobClient.access $ 700(JobClient.java:179)     在org.apache.hadoop.mapred.JobClient $ 2.run(JobClient.java:959)at   org.apache.hadoop.mapred.JobClient $ 2.run(JobClient.java:912)at   java.security.AccessController.doPrivileged(Native Method)at   javax.security.auth.Subject.doAs(Subject.java:422)at   org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:742)     在   org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:912)     在org.apache.hadoop.mapreduce.Job.submit(Job.java:500)at   org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:530)at at   hadoop.WordCount.main(WordCount.java:66)       引起:java.lang.ClassNotFoundException:org.apache.avro.io.DatumReader at at   java.net.URLClassLoader.findClass(URLClassLoader.java:381)at   java.lang.ClassLoader.loadClass(ClassLoader.java:424)at   sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:331)at at   java.lang.ClassLoader.loadClass(ClassLoader.java:357)

提前致谢。

1 个答案:

答案 0 :(得分:0)

如果此程序中的其余代码已更正; 我建议你检查路径 OutputPath文件夹不存在 我尝试过你的代码更改文件路径,代码可以正常运行

FileInputFormat.addInputPath(job, new Path("hdfs://localhost:9000/wordcount/test.txt"));
    FileOutputFormat.setOutputPath(job, new Path("hdfs://localhost:9000/wordcount/out"));