java getCredentials方法在试图通过导入所有JAR文件在eclipse中运行“单词计数”程序时出错
错误:线程“main”java中出现异常。lang.NoSuchMethodError:org。阿帕奇。hadoop。安全用户组信息。getCredentials()Lorg/apache/hadoop/security/Credentials; 在org。阿帕奇。hadoop。mapreduce。工作(Job.java:135) 在org。阿帕奇。hadoop。mapreduce。工作getInstance(Job.java:176) 在org。阿帕奇。hadoop。mapreduce。工作getInstance(Job.java:195) 在WordCount。main(WordCount.java:20)
Hadoop 2.2.0版
字数。java
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
public class WordCount {
public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.out.println("usage: [input] [output]");
System.exit(-1);
}
Job job = Job.getInstance(new Configuration(), "word count");
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setMapperClass(WordMapper.class);
job.setReducerClass(SumReducer.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
FileInputFormat.setInputPaths(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.setJarByClass(WordCount.class);
job.setJobName("WordCount");
job.submit();
}
}
WordMapper。java
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
public class WordMapper extends Mapper<Object, Text, Text, IntWritable> {
private Text word = new Text();
private final static IntWritable one = new IntWritable(1);
@Override
public void map(Object key, Text value,
Context contex) throws IOException, InterruptedException {
// Break line into words for processing
StringTokenizer wordList = new StringTokenizer(value.toString());
while (wordList.hasMoreTokens()) {
word.set(wordList.nextToken());
contex.write(word, one);
}
}
}
summer。java
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
public class SumReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
private IntWritable totalWordCount = new IntWritable();
@Override
public void reduce(Text key, Iterable<IntWritable> values, Context context)
throws IOException, InterruptedException {
int wordCount = 0;
Iterator<IntWritable> it=values.iterator();
while (it.hasNext()) {
wordCount += it.next().get();
}
totalWordCount.set(wordCount);
context.write(key, totalWordCount);
}
}
请告诉我能做什么?该程序使用了最新的mapreduce API。hadoop 2.2.0附带的所有JAR也被导入eclipse中
谢谢:)
# 1 楼答案
你是在使用一个用于Hadoop的Eclipse插件吗?如果不是,那就是问题所在。没有插件,Eclipse如果只是运行
WordCount
类,Hadoop就找不到必要的JAR。捆绑所有jar,包括WordCount
,并在集群中运行它如果你想从Eclipse运行它,你需要Eclipse插件。如果没有,可以按照以下instructions构建插件