I am new in Hadoop. I have installed the oracle virtual box for and mounted the image of hortonworks sandbox in the virtual machine.also i have written the wordcount program in eclipse and trying to run that in the virtual machine. But I am getting an exception tree. I am posting the program and the error tree also.
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]
Exception in thread main java.lang.NoClassDefFoundError:jar/usr/lib/wordcount/jar
caused by:java.lang.ClassNotFoundException:jar.usr.lib.wordcount.jar at java.net.URLClassLoader$1.run(URLlassLoader.java:202) at java.security.AccessController.doPriviledged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Laucher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
could not find the main class:jar/usr/lib/wordcount.jar
i am using the Hortonworks+Sandbox+1.3+VirtualBox+RC6 this version on a 64 bit machine .
You're not invoking hadoop correctly, you're missing a space, as well as args. Try
hadoop jar /usr/lib/wordcount.jar WordCount <the path to your input file on HDFS> <the path to your output directory on HDFS>
If you get another class not found, try using the full class name of WordCount (eg, com.mysite.WordCount). I can't see what package it's in.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.