Hadoop 1.2.1-“;java.lang.NoClassDefFoundError:org/apache/hadoop/mapred/JobConf";在mapreduce编译期间
我正在尝试学习如何使用Hadoop 1.2.1 我已经创建了第一个集群,但无法用java编译mapreduce示例(Eclipse 2021-03) 以下是我的源代码:Hadoop 1.2.1-“;java.lang.NoClassDefFoundError:org/apache/hadoop/mapred/JobConf";在mapreduce编译期间,java,hadoop,mapreduce,Java,Hadoop,Mapreduce,我正在尝试学习如何使用Hadoop 1.2.1 我已经创建了第一个集群,但无法用java编译mapreduce示例(Eclipse 2021-03) 以下是我的源代码: import java.io.*; import java.util.*; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.*; import org.apache.hadoop.mapred.*; import org.apache.hado
import java.io.*;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.mapred.Reducer;
public class WordCount {
public static class WordCountMapper extends MapReduceBase
implements Mapper<LongWritable, Text, Text, IntWritable> {
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, new IntWritable(1));
}
}
}
public static class WordCountReducer 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 total = 0;
while (values.hasNext()) {
total += values.next().get();
}
output.collect(key, new IntWritable(total));
}
}
public static void main(String[] args) throws Exception {
JobConf conf = new JobConf(WordCount.class);
conf.setJobName("Word Count");
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
conf.setMapperClass(WordCountMapper.class);
conf.setReducerClass(WordCountReducer.class);
conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);
FileInputFormat.addInputPath(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
JobClient.runJob(conf);
}
}
找不到JobConf类的原因是什么?
在引用的库中,我有hadoop-core-1.2.1.jar和hadoop目录中的其他库
有人能告诉我我做错了什么吗?:)
致以最良好的祝愿 您需要在项目中添加一些库。在Eclipse中制作一个可执行Jar。在Java中检查此错误
NoClassDefFoundError:
,您可以找到许多解决方案。
While trying to run application, it shows me this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/mapred/JobConf
at WordCount.main(WordCount.java:45)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.mapred.JobConf
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more