我是Hadoop的新手。我已经在虚拟机中安装了oracle虚拟盒并安装了hortonworks沙箱的映像。此外,我已经在eclipse中编写了wordcount程序并尝试在虚拟机中运行它。但是我得到了一个异常树。我也在发布程序和错误树。
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 IOException {
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);
}
}
[hue @ sandbox`] $ hadoop jar / usr / lib / wordcount.jar wordcount [-m] [ - r]
主线程java.lang.NoClassDefFoundError中的异常:jar / usr / lib / wordcount / jar
由找不到主类:jar / usr / lib / wordcount.jar
我在64位机器上使用Hortonworks + Sandbox + 1.3 + VirtualBox + RC6这个版本。
答案 0 :(得分:0)
你没有正确调用hadoop,你错过了一个空格,还有args。尝试
hadoop jar /usr/lib/wordcount.jar WordCount <the path to your input file on HDFS> <the path to your output directory on HDFS>
如果找不到另一个类,请尝试使用WordCount的完整类名(例如,com.mysite.WordCount)。我看不出它的包装。