如何在hadoop中指定系统属性,除了修改hadoop-env.sh? [英] How to specify system property in hadoop except modify hadoop-env.sh?
问题描述
我想在运行hadoop作业时设置系统属性(不是hadoop属性)。我发现设置系统属性并不容易。即使我在shell中设置属性
export HADOOP_OPTS =$ HADOOP_OPTS:-Dproperty = value
这仍然不起作用。 hadoop命令行的-D选项仅用于配置,而不是系统属性。所以-D选项也不起作用。
任何人有想法?谢谢
为什么不简单地使用 -Dfoo.bar = example
当通过命令行启动作业时,如下所示:
hadoop jar example.jar com.example.ExampleTool -Dfoo.bar = example参数
为了获得代码中的属性,使用 conf.get(foo.bar) ;
现在,如果您真的需要将其设置为系统属性,
String property = conf.get( foo.bar);
System.setProperty(foo.bar,property);
I'd like to set system property (not hadoop property) when running hadoop jobs. I found that it's not easy to setting system property. Even I set the property in shell
export HADOOP_OPTS="$HADOOP_OPTS:-Dproperty=value"
It's still not working. The "-D" option of hadoop command line is only for Configuration, not system property. So the "-D" option also not working
Anyone has ideas ? thanks
Why not simply use -Dfoo.bar=example
in-line when starting the job via command line, like so:
hadoop jar example.jar com.example.ExampleTool -Dfoo.bar=example argument
In order to get at the property in code, use conf.get("foo.bar");
Now if you genuinely need it to be set as a system property, you can set it at the start of your code using the value you got from Hadoop config like so:
String property = conf.get("foo.bar");
System.setProperty("foo.bar", property);
这篇关于如何在hadoop中指定系统属性,除了修改hadoop-env.sh?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!