一、使用Configuration
1、构建新的作业
Configuration conf=new Configuration(); Job job=Job.getInstance(conf); job.setJarByClass(MyWordCount.class);
2、设置输入输出目录
FileInputFormat.addInputPath(job, new Path("/wordcount")); FileOutputFormat.setOutputPath(job, new Path("/wordcount_result_2")); // 加/在根目录,不加/在家目录
3、设置Mapper+Reducer类
job.setMapperClass(MyMapper.class); job.setReducerClass(MyReduce.class);
4、设置输出格式
job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class);
5、提交执行作业
System.exit(job.waitForCompletion(true)?0:1);
二、使用Configured + Tool
1、构建新的作业
Configuration conf=getConf(); Job job=Job.getInstance(conf); job.setJarByClass(MaxTemp.class);
2、使用-Dinpath,-Doutpath输入输入输出路径
Path inpath=new Path(conf.get("inpath")); Path outpath=new Path(conf.get("outpath")); FileInputFormat.addInputPath(job, inpath); FileOutputFormat.setOutputPath(job, outpath);
3、设置Mapper+Reducer类
job.setMapperClass(MaxTempMapper.class); job.setReducerClass(MaxTempReducer.class);
4、设置Mapper Reducer输出类型
job.setOutputValueClass(IntWritable.class); job.setOutputKeyClass(IntWritable.class);
5、等待程序运行结束退出JVM
return job.waitForCompletion(true)?0:1;