需要帮助在horton works沙盒上运行修改后的wordcount程序

vof42yt1  于 2021-06-04  发布在  Hadoop
关注(0)|答案(1)|浏览(428)

运行wordcount程序的修改版本时出错(添加了Map器逻辑以将符号从单词中分离出来)。
错误:java.lang.runtimeexception:java.lang.classnotfoundexception:class wcount.wordcount$tokenizermapper
os:hortonworks沙盒托管2.6 hadoop版本我就是这么做的-
修改wordcount.java以引入Map器逻辑
使用命令编译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 使用创建wordcount.jar jar cvf wordcount.jar wcount (其中wcount是包含所有3个类(wordcount、tokenizer和intsumreducer)的文件夹)。下面是jar文件的样子 wcount wcount/WordCount.class wcount/WordCount$TokenizerMapper.class wcount/WordCount$intsumreducer.class 使用命令- 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 代码是

  1. package wcount;
  2. import java.io.IOException;
  3. import java.util.StringTokenizer;
  4. import org.apache.hadoop.conf.Configuration;
  5. import org.apache.hadoop.fs.Path;
  6. import org.apache.hadoop.io.IntWritable;
  7. import org.apache.hadoop.io.Text;
  8. import org.apache.hadoop.mapreduce.Job;
  9. import org.apache.hadoop.mapreduce.Mapper;
  10. import org.apache.hadoop.mapreduce.Reducer;
  11. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  12. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  13. import org.apache.hadoop.util.GenericOptionsParser;
  14. public class WordCount {
  15. public static class TokenizerMapper
  16. extends Mapper<Object, Text, Text, IntWritable>{
  17. private final static IntWritable one = new IntWritable(1);
  18. private Text word = new Text();
  19. public void map(Object key, Text value, Context context
  20. ) throws IOException, InterruptedException {
  21. StringTokenizer itr = new StringTokenizer(value.toString());
  22. char[] chararray = {'(' , ')' , ';' , ':' , '.' , '/' , '{' , '}' , ']' , ']'};
  23. String temp;
  24. while (itr.hasMoreTokens())
  25. {
  26. temp = itr.nextToken();
  27. for (short i = 0; i < chararray.length; i++)
  28. {
  29. if (temp.charAt(0) == chararray[i])
  30. {
  31. temp = temp.substring(1);
  32. }
  33. if (temp.charAt(temp.length() - 1) == chararray[i])
  34. {
  35. temp = temp.substring(0, temp.length() - 1);
  36. }
  37. }
  38. word.set(temp);
  39. context.write(word, one);
  40. }
  41. }
  42. }
  43. public static class IntSumReducer
  44. extends Reducer<Text,IntWritable,Text,IntWritable> {
  45. private IntWritable result = new IntWritable();
  46. public void reduce(Text key, Iterable<IntWritable> values,
  47. Context context
  48. ) throws IOException, InterruptedException {
  49. int sum = 0;
  50. for (IntWritable val : values) {
  51. sum += val.get();
  52. }
  53. result.set(sum);
  54. context.write(key, result);
  55. }
  56. }
  57. public static void main(String[] args) throws Exception {
  58. Configuration conf = new Configuration();
  59. String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
  60. if (otherArgs.length < 2) {
  61. System.err.println("Usage: wordcount <in> [<in>...] <out>");
  62. System.exit(2);
  63. }
  64. Job job = new Job(conf, "word count");
  65. job.setJarByClass(WordCount.class);
  66. job.setMapperClass(TokenizerMapper.class);
  67. job.setCombinerClass(IntSumReducer.class);
  68. job.setReducerClass(IntSumReducer.class);
  69. job.setOutputKeyClass(Text.class);
  70. job.setOutputValueClass(IntWritable.class);
  71. for (int i = 0; i < otherArgs.length - 1; ++i) {
  72. FileInputFormat.addInputPath(job, new Path(otherArgs[i]));
  73. }
  74. FileOutputFormat.setOutputPath(job,
  75. new Path(otherArgs[otherArgs.length - 1]));
  76. System.exit(job.waitForCompletion(true) ? 0 : 1);
  77. }
  78. }
sg2wtvxw

sg2wtvxw1#

您没有在作业设置中设置任何inputformatter,因此默认情况下,您的输入格式化程序是textinputformatter。所以这项工作可能需要一个 LongWritable 相对于普通的 Object . 你能换一下房间吗 extends Mapper<Objectextends Mapper<LongWritable 还有 map(Object keymap(LongWritable key ?

相关问题