Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The import org.apache.hadoop.mapreduce cannot be resolved

I am trying to execute the below code

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);
    }
}

But i am finding some error "The import org.apache.hadoop.mapreduce cannot be resolved" I have been already added Hadoop Jar file "http://www.java2s.com/Code/Jar/h/Downloadhadoop0210eclipsepluginjar.htm" .

Hadoop version-Hadoop 2.0.0-cdh4.2.0

Eclipse-juno Service Release 2 Can any one please help me to resole this issue.

like image 524
Indrajit Swain Avatar asked Jan 23 '26 22:01

Indrajit Swain


1 Answers

Try including the following external jars that you downloaded with Hadoop:

  • $HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-client-core-2.2.0.jar
  • $HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-client-common-2.2.0.jar
  • $HADOOP_HOME/share/hadoop/common/hadoop-common-2.2.0.jar
like image 98
Joan Salvatella Avatar answered Jan 25 '26 18:01

Joan Salvatella



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!