吃鱼的懒猫 2021-05-14 11:45 采纳率: 50%
浏览 198
已采纳

"main" java.lang.ClassNotFoundException怎么解决?

本人在自学MapReduce编程入门中,编写dailyAccessCount文件时运行:

编译生成dailyAccessCount.jar文件,提示有错误,我选择了yes

上传到Hadoop集群服务器节点,如图所示:

在Hadoop节点下执行命令时出现如标题所示异常,这是怎么回事?

dailyAccessCount代码如下:是代码出错了吗?还是什么原因?

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;

public class dailyAccessCount {

	public static class MyMapper extends Mapper<Object, Text, Text, IntWritable> {

		private final static IntWritable one = new IntWritable(1);

		public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
			String line = value.toString();
			String array[] = line.split(","); // 指定空格为分隔符,组成数组
			String keyOutput = array[1]; // 提取数组中的访问日期做为Key
			context.write(new Text(keyOutput), one); // 组成键值对
		}
	}

	public static class MyReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
		private IntWritable result = new IntWritable();

		public void reduce(Text key, Iterable<IntWritable> values, Context context)
				throws IOException, InterruptedException {
			int sum = 0; // 定义累加器,初始值为0
			for (IntWritable val : values) {
				sum += val.get(); // 将相同键的所有值进行累加
			}
			result.set(sum);
			context.write(key, result);
		}
	}

	public static void main(String[] args) throws Exception {

		Configuration conf = new Configuration();
		String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
		if (otherArgs.length < 2) {
			System.err.println("Usage: wordcount <in> [<in>...] <out>");
			System.exit(2);
		}
		Job job = new Job(conf, "Daily Access Count");
		job.setJarByClass(dailyAccessCount.class);
		job.setMapperClass(MyMapper.class);
		job.setReducerClass(MyReducer.class);
		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(IntWritable.class);

		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(IntWritable.class);
		for (int i = 0; i < otherArgs.length - 1; ++i) {
			FileInputFormat.addInputPath(job, new Path(otherArgs[i]));
		}
		FileOutputFormat.setOutputPath(job, new Path(otherArgs[otherArgs.length - 1]));
		System.exit(job.waitForCompletion(true) ? 0 : 1);
	}
}

eclipse编译环境我也调成和书上一样的了:jdk1.7

鼓捣了一上午,还没解决。。

  • 写回答

2条回答 默认 最新

  • 吃鱼的懒猫 2021-06-03 17:04
    关注

    我解决了,是在eclipse中打包生成jar包时出错了,没有勾选主类的问题。 

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 adb连接不到手机是怎么回事?
  • ¥15 vs2022无法联网
  • ¥15 TCP的客户端和服务器的互联
  • ¥15 VB.NET操作免驱摄像头
  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目