0
我知道這個問題已經被問過,但我似乎無法弄清楚。我有一個使用hadoop的單節點集羣設置,可以正常工作。我試圖編譯WordCount.java例如:創建Hadoop java示例
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.mapred.*;
import org.apache.hadoop.util.*;
public class WordCount {
public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
output.collect(word, one);
}
}
}
public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
int sum = 0;
while (values.hasNext()) {
sum += values.next().get();
}
output.collect(key, new IntWritable(sum));
}
}
public static void main(String[] args) throws Exception {
JobConf conf = new JobConf(WordCount.class);
conf.setJobName("wordcount");
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
conf.setMapperClass(Map.class);
conf.setCombinerClass(Reduce.class);
conf.setReducerClass(Reduce.class);
conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);
FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
JobClient.runJob(conf);
}
}
我已經安裝了Hadoop的2.2.0到/ usr /本地/ Hadoop的/但我不能爲我的生活弄清楚什麼.jar文件我需要添加eclipse來導入org.apache.hadoop文件。我很少使用Java或eclipse,但我已將hadoop home文件夾中的每個.jar文件複製到我的eclipse工作區中的lib文件夾中,並在項目設置中添加了外部.jars。任何想法我做錯了什麼?
感謝您的響應。我正在使用該教程,但是當我進入我的/ usr/local/hadoop和/ usr/local/hadoop/lib時,在任一目錄中都有0個.jar文件。 http://www.interior-dsgn.com/apache/hadoop/core/stable/hadoop-2.2.0.tar.gz是我用來下載它的鏡像。 – kirax
我最終搞清楚了。在2.2.0中.jar文件位於/ shared/hadoop /文件夾 – kirax
太好了,謝謝你的反饋。 – PNS