在CDH4示例中运行map减少作业

时间:2013-02-28 03:46:17

标签: java hadoop mapreduce

我是CDH4和Hadoop的新手。

我正在尝试运行wordcountexample并获得以下错误。 你能否纠正我,让我知道问题是什么:

WordCount.java:25: interface expected here
            public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
                                                                           ^
WordCount.java:39: interface expected here
            public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
                                                                               ^
WordCount.java:56: setMapperClass(java.lang.Class<? extends org.apache.hadoop.mapred.Mapper>) in org.apache.hadoop.mapred.JobConf cannot be applied to (java.lang.Class<WordCount.Map>)
              conf.setMapperClass(Map.class);
                  ^
WordCount.java:57: setCombinerClass(java.lang.Class<? extends org.apache.hadoop.mapred.Reducer>) in org.apache.hadoop.mapred.JobConf cannot be applied to (java.lang.Class<WordCount.Reduce>)
              conf.setCombinerClass(Reduce.class);
                  ^
WordCount.java:58: setReducerClass(java.lang.Class<? extends org.apache.hadoop.mapred.Reducer>) in org.apache.hadoop.mapred.JobConf cannot be applied to (java.lang.Class<WordCount.Reduce>)
              conf.setReducerClass(Reduce.class);
                  ^
WordCount.java:60: setInputFormat(java.lang.Class<? extends org.apache.hadoop.mapred.InputFormat>) in org.apache.hadoop.mapred.JobConf cannot be applied to (java.lang.Class<org.apache.hadoop.mapreduce.lib.input.TextInputFormat>)
              conf.setInputFormat(TextInputFormat.class);
                  ^
WordCount.java:63: cannot find symbol
symbol  : method setInputPaths(org.apache.hadoop.mapred.JobConf,org.apache.hadoop.fs.Path)
location: class org.apache.hadoop.mapreduce.lib.input.FileInputFormat
              FileInputFormat.setInputPaths(conf, new Path(args[0]));
                             ^
WordCount.java:64: setOutputPath(org.apache.hadoop.mapreduce.Job,org.apache.hadoop.fs.Path) in org.apache.hadoop.mapreduce.lib.output.FileOutputFormat cannot be applied to (org.apache.hadoop.mapred.JobConf,org.apache.hadoop.fs.Path)
              FileOutputFormat.setOutputPath(conf, new Path(args[1]));

用于编译的命令:

javac -classpath /usr/lib/hadoop/*:/usr/lib/hadoop/client/* WordCount.java 

计划是wordcountexample

2 个答案:

答案 0 :(得分:1)

问题在于-classpath选项。你需要给出绝对的罐子路径。 *已经不够了。将所有jars绝对路径分隔为:

答案 1 :(得分:1)

对于CHD4,请尝试:

$ javac -classpath 'hadoop classpath' WordCount.java