我已经采用了标准的wordcount程序 下面是标准示例代码
package myorg.org;
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);
}
}
我在eclipse中创建了一个java项目并添加了hadoop-common-2.0.0-cdh4.3.0.jar
和hadoop-core-2.0.0-mr1-cdh4.3.0
jar,因为我们正在使用Hadoop,它已成功编译并创建了jar文件并将该jar文件复制到边缘服务器中,然后我创建了2个示例输入文件,我运行hadoop jar命令,它说unable to open jar file
下面是我用于打开jar文件的命令
hadoop jar /home/a491882/Map-Reduce/WordCount.jar /home/a491882/Map-Reduce/input /home/a491882/Map-Reduce/output
我有jar文件存在于该位置并输入文件,但是无法找到为什么会出现此错误,在我们的hadoop集群中,我们正在使用hadoop-common-2.0.0-cdh4.3.0.jar和hadoop-core-2.0.0-mr1-cdh4.3.0 jar文件
请说明可能出现的问题。