java - 在 Horton Works 沙盒上运行 Modified Wordcount 程序时需要帮助。

标签 java hadoop jar word-count hortonworks-data-platform

我在运行修改版的 Wordcount 程序时遇到错误(添加了映射器逻辑以将符号与单词分开)。

错误:java.lang.RuntimeException:java.lang.ClassNotFoundException:类 wcount.WordCount$TokenizerMapper

操作系统:HortonWorks Sandbox hosting 2.6 Hadoop 版本 这是我所做的-

  1. 修改 Wordcount.java 以引入映射器逻辑
  2. 使用命令编译了 Wordcount.java javac -classpath/home/test_user/jars/commons-cli-1.2.jar:/home/test_user/jars/hadoop-common-2.6.0.2.2.0.0-2041.jar:/home/test_user/jars/hadoop-mapreduce-client-core-2.6.0.2.2.0.0-2041.jar -d/home/test_user/hadoopjar/wordcountclass -Xlint:deprecation WordCount.java
  3. 使用 jar cvf wordcount.jar wcount 创建了 WordCount.jar(其中 wcount 是包含所有 3 个类(wordcount、tokenizer 和 intsumreducer)的文件夹。 这是 jar 文件的样子 计数 wcount/WordCount.class 类 wcount/WordCount$TokenizerMapper.class 类 wcount/WordCount$intsumreducer.class

  4. 使用命令运行它 - hadoop jar wordcount.jar WordCount/home/user/test_user/wordcount/wordcount.txt/home/user/test_user/wordcount/out8

尝试运行 Map 作业后出错 Error: java.lang.RuntimeException: java.lang.ClassNotFoundException: Class wcount.WordCount$TokenizerMapper

代码是

package wcount;

import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;

public class WordCount {

  public static class TokenizerMapper
       extends Mapper<Object, Text, Text, IntWritable>{

    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();

    public void map(Object key, Text value, Context context
                    ) throws IOException, InterruptedException {
      StringTokenizer itr = new StringTokenizer(value.toString());
       char[] chararray = {'(' , ')' , ';' , ':' , '.' , '/' , '{' , '}' , ']' , ']'};
       String temp;
      while (itr.hasMoreTokens())
      {
          temp = itr.nextToken();
          for (short i = 0; i < chararray.length; i++)
          {
              if (temp.charAt(0) == chararray[i])
              {
                  temp = temp.substring(1);
              }
           if (temp.charAt(temp.length() - 1) == chararray[i])
              {
                  temp = temp.substring(0, temp.length() - 1);
              }
          }
        word.set(temp);
        context.write(word, one);
      }
    }
  }

  public static class IntSumReducer
       extends Reducer<Text,IntWritable,Text,IntWritable> {
    private IntWritable result = new IntWritable();

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

  public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
    if (otherArgs.length < 2) {
      System.err.println("Usage: wordcount <in> [<in>...] <out>");
      System.exit(2);
    }
    Job job = new Job(conf, "word count");
    job.setJarByClass(WordCount.class);
    job.setMapperClass(TokenizerMapper.class);
    job.setCombinerClass(IntSumReducer.class);
    job.setReducerClass(IntSumReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    for (int i = 0; i < otherArgs.length - 1; ++i) {
      FileInputFormat.addInputPath(job, new Path(otherArgs[i]));
    }
    FileOutputFormat.setOutputPath(job,
      new Path(otherArgs[otherArgs.length - 1]));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
  }
}

最佳答案

您没有在作业设置中设置任何 InputFormatter,因此默认情况下您的输入格式化程序是 TextInputFormatter。所以这份工作可能需要一个LongWritable而不是普通的 Object .您可以尝试更改 extends Mapper<Object 吗?至 extends Mapper<LongWritable还有map(Object keymap(LongWritable key

关于java - 在 Horton Works 沙盒上运行 Modified Wordcount 程序时需要帮助。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28153347/

相关文章:

java - 通过蓝牙服务名称连接

java - Android - 当事件发生在不同的类上时得到通知

java - 在 Windows 7 中尝试 Hadoop 2.5.1 WordCount 教程时出现 UnsatisfiedLinkError

java - 如何在 Maven 中创建没有 meta-inf 文件夹的 jar?

作为 JAR 项目运行的 Spring JMS

java - 错误: package generated.架构不存在

java - 使用通配符验证 IP 地址

hadoop - HBase MapReduce ,多表操作

hadoop - 如何检查HDFS上文件的格式?

java - .jar 中的 .so (Eclipse)