首页 > 解决方案 > 如何修复运行 Hadoop 程序的 Eclipse 中的 InputBootStrapper 错误?

问题描述

我该如何解决?此代码是 JAVA 中的 Hadoop WordCount 示例。我已经添加了外部 JAR,这不是编译时问题,当我尝试运行程序时,这种情况正在发生。设置输入和输出参数。所有的经理都已启动并运行。

Hadoop 版本 2.9.0

Java 版本 1.8.0

日食氧气

操作系统 Ubuntu 14.04 64 位

可能是什么问题?

wordcount.java

package mapreduce;

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;

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());
  while (itr.hasMoreTokens()) {
    word.set(itr.nextToken());
    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();
Job job = Job.getInstance(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);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}

控制台(错误)

 Exception in thread "main" java.lang.NoClassDefFoundError: com/ctc/wstx/io/InputBootstrapper
    at mapreduce.wordcount.main(wordcount.java:51)
 Caused by: java.lang.ClassNotFoundException:  com.ctc.wstx.io.InputBootstrapper
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more

标签: javahadoopmapreduce

解决方案


对我来说缺少 jar 是这样的:hadoop-client-runtime.jar。从 Maven 添加额外的依赖项解决了问题。

作为一个附注,下面是我的依赖项列表(我使用的是 SBT/Scala):

libraryDependencies ++= Seq(
  "org.apache.hadoop" % "hadoop-client-api" % "3.3.1",
  "commons-logging" % "commons-logging" %  "1.2",
  "org.slf4j" % "slf4j-api" % "1.7.35",
  "org.apache.hadoop" % "hadoop-client-runtime" % "3.3.1"
)

此链接帮助我找到正确的方向:https ://issues.apache.org/jira/browse/SPARK-33343


推荐阅读