java - 运行 map 缩减程序时出现错误 java.lang.RuntimeException : java. lang.ClassNotFoundException : wordcount_classes. WordCount$Map

标签 java hadoop

我是 Hadoop 的新手,正在尝试运行 Map reduce 程序,即 Word Count,我收到以下错误 java.lang.RuntimeException: java.lang.ClassNotFoundException: wordcount_classes.WordCount$Map and 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. 您是否从 jar 包含的文件夹运行 或
  3. 使用以下命令运行

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

关于java - 运行 map 缩减程序时出现错误 java.lang.RuntimeException : java. lang.ClassNotFoundException : wordcount_classes. WordCount$Map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26176985/

相关文章:

hadoop - Hive命令给出错误

hadoop - 如何为 Multi-Tenancy 配置 Hive Impala/Spark?

ubuntu - Ambari 安装与其余的 hadoop 生态系统

logging - HBase 中的日志文件

hadoop - 在hcatalog正则表达式或serde中解析日志文件

java - Jenkins :https.protocols

Java - 打开大量文件并搜索单词的最佳方法?

java - jBehave生成系统的 'live documentation'

java - 允许自动查询的网络搜索 API

java - Android Studio构建失败,出现异常任务':app:dexDebug'的执行失败