2

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

1
  • Can we see the command you are using to start your job? Are you using a ToolRunner or GenericOptionsParser at all? Commented Mar 20, 2013 at 10:14

2 Answers 2

7

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);
Sign up to request clarification or add additional context in comments.

2 Comments

The reason is that I am using a library which need to get system property
I see, I've edited my answer to a potential solution for you.
4

The hadoop script invoke java class like this

exec "$JAVA" $JAVA_HEAP_MAX $HADOOP_OPTS $CLASS "$@"

so, we can pass system-wide property like this:

export HADOOP_OPTS="$HADOOP_OPTS -Dfoo=bar"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.