GenericOptionsParser 命令行解析器
是hadoop框架中解析命令行参数的基本类。它能够辨别一些标准的命令行参数,能够使应用程序轻易地指定namenode,jobtracker,以及其他额外的配置资源
有篇日志写的很好,自己就不赘述了:传送门
例子:
最简单的在WordCount中用到了:
Configuration conf = new Configuration();
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
if (otherArgs.length != 2) {
System.err.println("Usage: wordcount <in> <out>");
System.exit(2);
}
Job job = new Job(conf, "word count");
job.setJarByClass(WordCount.class);
job.setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
比如运行命令为:bin/hadoop dfs -fs master:8020 -ls /data
GenericOptionsParser把 -fs master:8020配置到配置conf中
而getRemainingArgs()方法则得到剩余的参数,就是 -ls /data。供下面使用输入输出参数
原文链接:https://www.cnblogs.com/admln/p/trivial-aboutGenericOptionsParser.html