在windows中使用debug执行hadoop程序

首先,你得先搭建hadoop项目,推荐地址

https://blog.****.net/lu1171901273/article/details/88395474

编写hadoop程序

package cn.lx.bigdata.mr.wcdemo;

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.lib.input.CombineTextInputFormat;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/**
 * 相当于一个yarn集群的客户端
 * 需要在此封装我们的mr程序的相关运行参数,指定jar包
 * 最后提交给yarn
 * @author
 *
 */
public class WordcountDriver2 {
	
	public static void main(String[] args) throws Exception {
		Configuration conf = new Configuration();
		
		//是否运行为本地模式,就是看这个参数值是否为local,默认就是local
		/*conf.set("mapreduce.framework.name", "local");*/
		
		//本地模式运行mr程序时,输入输出的数据可以在本地,也可以在hdfs上
		//到底在哪里,就看以下两行配置你用哪行,默认就是file:///
//		conf.set("fs.defaultFS", "hdfs://192.168.124.140:9000/");
		/*conf.set("fs.defaultFS", "file:///");*/
		Job job = Job.getInstance(conf);
		
		//指定本程序的jar包所在的本地路径
		job.setJarByClass(WordcountDriver2.class);
		
		//指定本业务job要使用的mapper/Reducer业务类
		job.setMapperClass(WordcountMapper.class);
		job.setReducerClass(WordcountReducer.class);
		
		//指定mapper输出数据的kv类型
		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(IntWritable.class);
		
		//指定最终输出的数据的kv类型
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(IntWritable.class);
		
		//指定需要使用combiner,以及用哪个类作为combiner的逻辑
		/*job.setCombinerClass(WordcountCombiner.class);*/
		job.setCombinerClass(WordcountReducer.class);
		
		//如果不设置InputFormat,它默认用的是TextInputformat.class
		job.setInputFormatClass(CombineTextInputFormat.class);
		CombineTextInputFormat.setMaxInputSplitSize(job, 4194304);
		CombineTextInputFormat.setMinInputSplitSize(job, 2097152);

		//指定job的输入原始文件所在目录
		FileInputFormat.setInputPaths(job, new Path("D://hadoop//test//input"));
		//指定job的输出结果所在目录
		FileOutputFormat.setOutputPath(job, new Path("D://hadoop//test//output"));
		
		//将job中配置的相关参数,以及job所用的java类所在的jar包,提交给yarn去运行
		/*job.submit();*/
		boolean res = job.waitForCompletion(true);
		System.exit(res?0:1);
		
	}
}

使用debug模式执行

在windows中使用debug执行hadoop程序

 执行成功

在windows中使用debug执行hadoop程序