Question

I am trying to set properties for an oozieclient in java which are read from a properties file. The properties file has 10 odd properties. Is there a way I can set these properties all at once and not have to read each key value pair from the file and then set them for the oozieclient?

OozieClient wc = new OozieClient(http://something:1100/oozie);

Properties conf = wc.createConfiguration();
conf.setProperty("jobTracker",....);
conf.setProperty("nameNode",......);
.
.
.

Instead of this, is there a way in which i can read these values from a properties file and set the values all at once?

Was it helpful?

Solution

You can read another property file and merge both:

OozieClient wc = new OozieClient("http://something:1100/oozie");

Properties conf = wc.createConfiguration();
Properties p = new Properties();
FileInputStream fis = new FileInputStream("myfile.properties");
p.load(fis);
conf.putAll(p);
fis.close(); // you still need to close the stream

With the file myfile.properties like:

jobTracker=foo
nameNode=bar

Take a look at the Javadoc for Properties

OTHER TIPS

Check out the following API: Oracle Docs. The load() operations on Properties can be given a reference to the .properties FileInputSteam or FileInputReader , it will read out all key-value pairs into your Properties-object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top