网上很多回答,都是:
yarn jar app.jar com.xxx.mainClass -D mapreduce.job.queuename=default args1 args2
但是这样设置并不能生效!!!!!是有问题的!!!!!
网上的所有设置都是基于hadoop官方的example。
example中有这样一段代码。
会将-D的配置进行处理,加入到Configuration中
以wordcount为例
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
//!!!这里会处理一些系统参数。之后会留下其他用户真正想传入的其他参数otherArgs
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
if (otherArgs.length < 2) {
System.err.println("Usage: wordcount <in> [<in>...] <out>");
System.exit(2);
}
/**GenericOptionsParser 中处理-D */
if (line.hasOption('D')) {
String[] property = line.getOptionValues('D');
for(String prop : property) {
String[] keyval = prop.split("=", 2);
if (keyval.length == 2) {
conf.set(keyval[0], keyval[1], "from command line");
}
}
}
因此用户编程时建议加上这段配置。
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
便于传入外部系统参数。