簡體   English   中英

運行地圖精簡程序時出現錯誤java.lang.RuntimeException:java.lang.ClassNotFoundException:wordcount_classes.WordCount $ Map

[英]Error java.lang.RuntimeException: java.lang.ClassNotFoundException: wordcount_classes.WordCount$Map while running the map reduce program

我是Hadoop的新手,並嘗試運行Map減少程序,即字數統計,並且遇到以下錯誤java.lang.RuntimeException:java.lang.ClassNotFoundException:wordcount_classes.WordCount $ Map和WordCount.java

import java.io.IOException;
import java.util.*;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

public class WordCount {

public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> {
   private final static IntWritable one = new IntWritable(1);
   private Text word = new Text();

   public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
       String line = value.toString();
       StringTokenizer tokenizer = new StringTokenizer(line);
       while (tokenizer.hasMoreTokens()) {
           word.set(tokenizer.nextToken());
           context.write(word, one);
       }
   }
} 

public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {

   public void reduce(Text key, Iterable<IntWritable> values, Context context) 
     throws IOException, InterruptedException {
       int sum = 0;
       for (IntWritable val : values) {
           sum += val.get();
       }
       context.write(key, new IntWritable(sum));
   }
}

public static void main(String[] args) throws Exception {
   Configuration conf = new Configuration();

      Job job = new Job(conf, "wordcount");

   job.setOutputKeyClass(Text.class);
   job.setOutputValueClass(IntWritable.class);

   job.setMapperClass(Map.class);
   job.setReducerClass(Reduce.class);

   job.setInputFormatClass(TextInputFormat.class);
   job.setOutputFormatClass(TextOutputFormat.class);

   FileInputFormat.addInputPath(job, new Path(args[0]));
   FileOutputFormat.setOutputPath(job, new Path(args[1]));
   job.setJarByClass(WordCount.class);    
   job.waitForCompletion(true);
}

wordcount_classes目錄的內容是

-rw-r--r--   1 sagar supergroup       1855 2014-10-03 13:15 /user/sagar  /wordcount_classes/WordCount$Map.class
-rw-r--r--   1 sagar supergroup       1627 2014-10-03 13:15 /user/sagar/wordcount_classes/WordCount$Reduce.class
-rw-r--r--   1 sagar supergroup       1453 2014-10-03 13:14 /user/sagar/wordcount_classes/WordCount.class
-rw-r--r--   1 sagar supergroup       3109 2014-10-03 13:15 /user/sagar/wordcount_classes/wordcount.jar

}

我正在通過以下命令編譯程序

hadoop jar wordcount_classes/wordcount.jar wordcount_classes/WordCount input r1

請檢查以下內容:

  1. 您是否將其編譯為可運行的jar
  2. 您是從罐子包含的文件夾中運行還是
  3. 使用以下命令運行

      hadoop jar <path_to_jar>/wordcount.jar WordCount <hdfs_path_to_input>/input <hdfpath>/r1 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM