java - java.lang.NoSuchMethodError:org.apache.hadoop.conf.Configuration.addDeprecation(Ljava/lang/String; [Ljava/lang/String;)

标签 java eclipse hadoop mapreduce

我正在使用Java / Eclipse / Hadoop 2.2.0(带有所有必要的jar)在Ubuntu上使用以下代码运行示例Map Reduce任务(本地单节点),但遇到了异常(下面的stacktrace)。

我可以从ubuntu控制台在Hadoop中运行示例字数示例。

码:

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.input.KeyValueTextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class testhdfs
{
    public static class WordMapper extends Mapper<Text, Text, Text, Text>
    {
        private Text word = new Text();
        public void map(Text key, Text value, Context context) throws IOException, InterruptedException
        {
            StringTokenizer itr = new StringTokenizer(value.toString(),",");
            while (itr.hasMoreTokens())
            {
                word.set(itr.nextToken());
                context.write(key, word);
            }
        }
    }
    public static class AllTranslationsReducer
    extends Reducer<Text,Text,Text,Text>
    {
        private Text result = new Text();
        public void reduce(Text key, Iterable<Text> values,
        Context context
        ) throws IOException, InterruptedException
        {
            String translations = "";
            for (Text val : values)
            {
                translations += "|"+val.toString();
            }
            result.set(translations);
            context.write(key, result);
        }
    }
    public static void main(String[] args) throws Exception
    {
        Configuration conf = new Configuration();
        Job job = new Job(conf, "dictionary");
        job.setJarByClass(testhdfs.class);
        job.setMapperClass(WordMapper.class);
        job.setReducerClass(AllTranslationsReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);
        job.setInputFormatClass(KeyValueTextInputFormat.class);
        FileInputFormat.addInputPath(job, new Path("/testext"));
        FileOutputFormat.setOutputPath(job, new Path("resulthdfs"));
        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}

堆栈跟踪:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.hadoop.conf.Configuration.addDeprecation(Ljava/lang/String;[Ljava/lang/String;)V
    at org.apache.hadoop.mapreduce.util.ConfigUtil.addDeprecatedKeys(ConfigUtil.java:53)
    at org.apache.hadoop.mapreduce.util.ConfigUtil.loadResources(ConfigUtil.java:41)
    at org.apache.hadoop.mapreduce.Job.<clinit>(Job.java:108)
    at testhdfs.main(testhdfs.java:49)

最佳答案

NoSuchMethodError异常几乎总是意味着您有一些奇怪的dependency问题,并且输入了错误的jar或缺少jar

关于java - java.lang.NoSuchMethodError:org.apache.hadoop.conf.Configuration.addDeprecation(Ljava/lang/String; [Ljava/lang/String;),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22740007/

相关文章:

java - 从 Matlab 内部调用 JAX-WS Web 服务

java - 显示另一个类的多个数组列表

java - 有谁知道一些返回操作系统友好文件名的 Java 类?

php - 我可以在 PHP 中使用 Hadoop 吗?

amazon-web-services - 无法将 AWS 主机注册到 Ambari 服务器

java - Objectify - java.lang.IllegalStateException : Embedded Map keys must be of type String/Enum/Key<? > 或字段必须指定@Stringify

java - Eclipse导入项目时出现错误 'could not determine Java version'

java - myeclipse 中的 F4 快捷键及其在 IntelliJ idea 中的等效快捷键

java - ANTLR myParser.java 未生成

格式化节点时Hadoop unknownhostexception