简体   繁体   English

线程“main”中的异常java.lang.ClassNotFoundException:WordCount

[英]Exception in thread “main” java.lang.ClassNotFoundException: WordCount

I am currently wanting to create a single instance node of Hadoop. 我目前想要创建Hadoop的单个实例节点。 So I am following this tutorial . 所以我正在学习本教程 I ran the following command in terminal: 我在终端中运行了以下命令:

hduser@ubuntu:/usr/local/hadoop$ bin/hadoop jar WordCount.jar geekyomega.WordCount /user/hduser/gutenberg /user/hduser/gutenberg-output

Things were going great until I ran into this error: 在遇到这个错误之前,事情进展顺利:

Exception in thread "main" java.lang.ClassNotFoundException: WordCount
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:270)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:153)

I am attempting to run this example using the following code, where I got from here . 我试图使用以下代码运行此示例,我从这里获得 Here is my version of the code: 这是我的代码版本:

package geekyomega;

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.mapreduce.*;
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 class Map extends 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, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        StringTokenizer tokenizer = new StringTokenizer(line);
        while (tokenizer.hasMoreTokens()) {
            word.set(tokenizer.nextToken());
            context.write(word, one);
        }
    }
 } 

 public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {

    public void reduce(Text key, Iterable<IntWritable> values, Context context) 
      throws IOException, InterruptedException {
        int sum = 0;
        for (IntWritable val : values) {
            sum += val.get();
        }
        context.write(key, new IntWritable(sum));
    }
 }

 public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();

    Job job = new Job(conf, "WordCount");

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);

    job.setMapperClass(Map.class);
    job.setReducerClass(Reduce.class);

    job.setInputFormatClass(TextInputFormat.class);
    job.setOutputFormatClass(TextOutputFormat.class);

    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));

    job.waitForCompletion(true);
 }

}

I thought my issue was job instantiation. 我认为我的问题是工作实例化。 So I did as follows, I changed: 所以我做了如下,我改变了:

Job job = new Job(conf, "wordcount");

To the following, capitalized version: 以下是大写版本:

Job job = new Job(conf, "WordCount");

But that hasn't helped. 但这没有帮助。 Anyone know what could help me here? 有人知道什么可以帮助我吗?

Thanks, Geeky 谢谢,Geeky

PS - I don't want to run the tutorial version of wordcount. PS - 我不想运行wordcount的教程版本。 What I did was created the project in eclipse, added the hadoop jar to it, and exported it as a jar file. 我所做的是在eclipse中创建了项目,将hadoop jar添加到它,并将其导出为jar文件。

your classname is geekyomega.WordCount 你的classname是geekyomega.WordCount

you are not appending the package name . 您没有附加包名称。 in the command line , just after jar file name, give the fully qualified name of your job class. 在命令行中,在jar文件名后面,给出作业类的完全限定名称。

Along with adding the package add the following line as well in the job config part of your program : 除了添加包之外,还在程序的作业配置部分添加以下行:

job.setJarByClass(WordCount.class); job.setJarByClass(WordCount.class);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 线程“ main”中的异常java.lang.ClassNotFoundException:tn.hadoop.WordCount - Exception in thread “main” java.lang.ClassNotFoundException: tn.hadoop.WordCount 线程“主”中的异常java.lang.ClassNotFoundException? - Exception in thread “main” java.lang.ClassNotFoundException? 线程“main”java.lang.ClassNotFoundException中的异常: - Exception in thread “main” java.lang.ClassNotFoundException: 线程“main”中的异常 java.lang.ClassNotFoundException,mapreduce - Exception in thread "main" java.lang.ClassNotFoundException, mapreduce Class.forName 中的线程“main”java.lang.ClassNotFoundException 中的异常 - Exception in thread "main" java.lang.ClassNotFoundException in Class.forName 线程“主”中的异常java.lang.ClassNotFoundException:TrackPlayer.MainTrack - Exception in thread “main” java.lang.ClassNotFoundException: TrackPlayer.MainTrack 线程“主”中的异常java.lang.ClassNotFoundException:MaxTemperature - Exception in thread “main” java.lang.ClassNotFoundException:MaxTemperature Docker 错误:线程“主”java.lang.ClassNotFoundException 中的异常 - Docker error: Exception in thread "main" java.lang.ClassNotFoundException HADOOP :: java.lang.ClassNotFoundException:WordCount - HADOOP :: java.lang.ClassNotFoundException: WordCount 线程“主”中的异常java.lang.NoClassDefFoundError:MyFile原因:java.lang.ClassNotFoundException: - Exception in thread “main” java.lang.NoClassDefFoundError: MyFile Caused by: java.lang.ClassNotFoundException:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM