請看看下面的代碼的Map Reduce:Unabale運行的代碼由於錯誤的數量
Map.java
public class Map extends Mapper<longwritable, intwritable="" text,=""> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
@Override
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
context.write(word, one);
}
}
}
</longwritable,>
Reduce.java
public class Reduce extends Reducer<text, intwritable,="" intwritable="" text,=""> {
@Override
protected void reduce(
Text key,
java.lang.Iterable<intwritable> values,
org.apache.hadoop.mapreduce.Reducer<text, intwritable,="" intwritable="" text,="">.Context context)
throws IOException, InterruptedException {
int sum = 0;
for (IntWritable value : values) {
sum += value.get();
}
context.write(key, new IntWritable(sum));
}
}
</text,></intwritable></text,>
WordCount.java
public class WordCount {
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = new Job(conf, "wordcount");
job.setJarByClass(WordCount.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setMapperClass(Map.class);
job.setReducerClass(Reduce.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.waitForCompletion(true);
}
}
這整個代碼是從thisMap Reduce
教程(http://cloud.dzone.com/articles/how-run-elastic-mapreduce-job)
萃取。只要我將這些類複製到Eclipse中,就會顯示很多錯誤,例如不能是Resolved By Type
。這是合理的,因爲這些代碼在實例中使用的類不在哪裏可以找到默認的JDK,並且本教程還沒有給出任何指令來下載任何庫。我忽略它認爲它與服務器端的Elastic Map Reduce
有關。
只要我上傳這對亞馬遜彈性的Map Reduce,創建一個作業流程和運行程序,它給了我下面的錯誤。
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Configuration cannot be resolved to a type
Configuration cannot be resolved to a type
Job cannot be resolved to a type
Job cannot be resolved to a type
Text cannot be resolved to a type
IntWritable cannot be resolved to a type
TextInputFormat cannot be resolved to a type
TextOutputFormat cannot be resolved to a type
FileInputFormat cannot be resolved
Path cannot be resolved to a type
FileOutputFormat cannot be resolved
Path cannot be resolved to a type
at WordCount.main(WordCount.java:5)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.main(RunJar.java:187)
我該如何使這段代碼有效?我必須爲此下載任何圖書館嗎?我如何讓這段代碼運行並查看結果?這是我第一次在亞馬遜和彈性地圖方面的經驗減少,是的,也是第一次使用大數據的經驗。
請幫忙。
感謝您的答覆。這個罐子在哪裏?我只複製該代碼並運行它 – Dongle
您可以從http://www.cloudera.com/content/support/en/downloads.html下載hadoop-client.xxx.jar,選擇要添加的版本。另外apach-hadoop也是如此:http://hadoop.apache.org/releases.html但是,如果你想在亞馬遜服務器上運行你的任務,你必須讓你選擇的hadoop版本是相同的到亞馬遜服務器。我不知道亞馬遜使用了哪個版本,也許他們打開了api或文檔資料,你可以檢查它。 – zxz