无法解析导入org.apache.hadoop.mapreduce

eqoofvh9  于 2021-06-03  发布在  Hadoop
关注(0)|答案(2)|浏览(862)

我正在尝试执行下面的代码

package test;

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.util.*;

import org.apache.hadoop.mapreduce.Mapper;

import org.apache.hadoop.mapreduce.Reducer;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.conf.Configured;

import org.apache.hadoop.mapreduce.Job;

import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;

import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class Diction {

    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(Dictionary.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("/tmp/hadoop-cscarioni/dfs/name/file"));
        FileOutputFormat.setOutputPath(job, new Path("output"));
        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}

但我发现了一些错误 import org.apache.hadoop.mapreduce 无法解析“我已经添加了hadoop jar文件”http://www.java2s.com/code/jar/h/downloadhadoop0210eclipsepluginjar.htm" .
hadoop版本hadoop 2.0.0-cdh4.2.0
EclipseJuno服务版本2能否有任何一个请帮助我解决这个问题。

s5a0g9ez

s5a0g9ez1#

你没有适当的依赖关系。实际上,您有一个用于hadoop开发的eclipse插件,它与hadoop的jar完全不同。
看看hadoop-0.21.0-eclipse-plugin.jar的内容,有没有看到hadoop核心类?
检查hadoop发行版并将真正的hadoop依赖项添加到构建工具(maven、ant、gradle…)。
如果您使用的是maven:

<dependency>
  <groupId>org.apache.hadoop</groupId>
  <artifactId>hadoop-client</artifactId>
  <version>2.2.0</version>
</dependency>
daupos2t

daupos2t2#

尝试包含以下使用hadoop下载的外部JAR:
$hadoop\u home/share/hadoop/mapreduce/hadoop-mapreduce-client-core-2.2.0.jar
$hadoop\u home/share/hadoop/mapreduce/hadoop-mapreduce-client-common-2.2.0.jar
$hadoop\u home/share/hadoop/common/hadoop-common-2.2.0.jar

相关问题