Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.isea.mapreduce;
- 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.FileInputFormat;
- import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
- import java.io.IOException;
- public class WordCountDriver {
- public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
- args = new String[]{"G:/input/input1/wordcount.txt","g:/output/output1"};
- //获取Job的配置信息
- Configuration configuration = new Configuration();
- //获取job
- Job job = Job.getInstance(configuration);
- //设置jar包的加载路径
- job.setJarByClass(WordCountDriver.class);
- //关联Mapper和Reducer的逻辑类
- job.setMapperClass(WordCountMapper.class);
- job.setReducerClass(WordCountReducer.class);
- //设置Mapper的输出的key和value的类型
- job.setMapOutputKeyClass(Text.class);
- job.setOutputValueClass(IntWritable.class);
- //设置最后的输出的key和value的类型
- job.setOutputKeyClass(Text.class);
- job.setOutputValueClass(IntWritable.class);
- //设置输入输出路径
- FileInputFormat.setInputPaths(job,new Path(args[0]));
- FileOutputFormat.setOutputPath(job,new Path(args[1]));
- boolean result = job.waitForCompletion(true);
- System.exit(result ? 0 : 1);
- }
- }
Add Comment
Please, Sign In to add comment