gpt4 book ai didi

java - Hadoop Java错误:线程 “main”中的异常java.lang.ClassNotFoundException:泰坦尼克号

转载 作者:行者123 更新时间:2023-12-02 21:13:06 25 4
gpt4 key购买 nike

我正在尝试运行一个简单的MapReduce程序,该程序计算男性和女性的平均年龄。当我尝试执行它时,它给了我Class Not Found Exception(泰坦尼克类)。我发现许多问题都提供了相似的答案,并且基于这些问题,我修改了程序,但仍然给我同样的错误。如果任何人都可以调试它会非常有帮助。

import java.io.IOException;
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 Titanic{
public static class Map extends Mapper<LongWritable, Text, Text, IntWritable>{
private Text category = new Text();
public void map(LongWritable key, Text text, Context context) throws IOException, InterruptedException{
String line = text.toString();
String str[] = line.split(",");
if(str[4] == "male"){
category.set(str[4]);
}else{
category.set(str[4]);
}
IntWritable value = new IntWritable(Integer.parseInt(str[5]));
context.write(category,value);
}

}

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

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

}

}

public static void main(String[] args) throws Exception{
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "titanic");
job.setJarByClass(Titanic.class);
job.setMapperClass(Map.class);
job.setReducerClass(Reduce.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}

}

以下是我已对其执行的命令。

创建一个jar文件:
jar cf example/titanic/titanic.jar example/titanic/Titanic*.class

执行一个jar文件:
bin/hadoop jar example/titanic/titanic.jar Titanic /user/akhil/titanic/input/TitanicData.txt /user/akhil/titanic/output/

最佳答案

jar 已经烂了。如果您的类属于默认软件包,则它们不应位于example/titanic/目录下,而应位于根目录下。

关于java - Hadoop Java错误:线程 “main”中的异常java.lang.ClassNotFoundException:泰坦尼克号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39647108/

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