content: package com.hzcortex.wordcount;
  
  import org.apache.hadoop.conf.Configuration;
  import org.apache.hadoop.conf.Configured;
  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.input.TextInputFormat;
  import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
  import org.apache.hadoop.util.Tool;
  import org.apache.hadoop.util.ToolRunner;
  
  /**
   * Created by allianzcortex on 17-4-23.
   */
  public class WordCountApp extends Configured implements Tool  {
  
      public int run(String[] args) throws Exception {
  
          if(args.length<2){
              throw new IllegalArgumentException("You must specify the input and output directory," +
                      "recommend use input/ and output/,and both dir should be prallel with src dir");
          }
          // TODO if output directory already exists,should delete dir
  
          final Configuration conf = this.getConf();
          final Job job = Job.getInstance(conf, "Word Count");
          job.setJarByClass(WordCountApp.class);
  
          job.setMapperClass(WordCountMapper.class);
          job.setReducerClass(WordCountReducer.class);
          job.setOutputKeyClass(Text.class);
          job.setOutputValueClass(IntWritable.class);
  
          job.setInputFormatClass(TextInputFormat.class);
          job.setOutputFormatClass(TextOutputFormat.class);
  
          FileInputFormat.addInputPath(job, new Path(args[0]));        FileOutputFormat.setOutputPath(job, new Path(args[1]));
  
          return job.waitForCompletion(true) ? 0 : 1;
  
      }
  
      public static void main(final String[] args) throws Exception {
          final int returnCode = ToolRunner.run(new Configuration(), new WordCountApp(), args);
  
          System.exit(returnCode);
      }
  }
  