gpt4 book ai didi

java - 线程 "main"java.lang.ClassNotFoundException : WordCount 中的异常

转载 作者:可可西里 更新时间:2023-11-01 14:11:54 29 4
gpt4 key购买 nike

我目前想创建 Hadoop 的单个实例节点。所以我关注这个tutorial .我在终端中运行了以下命令:

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

在我遇到这个错误之前一切都很顺利:

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)

我正在尝试使用以下代码运行此示例,我从 here 获得的代码.这是我的代码版本:

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);
}

}

我认为我的问题是作业实例化。所以我做了如下,我改变了:

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

以下,大写版本:

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

但这并没有帮助。有人知道什么可以帮助我吗?

谢谢,极客

PS - 我不想运行 wordcount 的教程版本。我所做的是在 eclipse 中创建项目,向其中添加 hadoop jar,并将其导出为 jar 文件。

最佳答案

你的类(class)名字是 geekyomega.WordCount

您没有附加包名。在命令行中,紧跟在 jar 文件名之后,给出作业类的完全限定名称。

关于java - 线程 "main"java.lang.ClassNotFoundException : WordCount 中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18796443/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com