abhinavkulkarni
abhinavkulkarni

Reputation: 2409

Hadoop Configuration.addDefaultResource() not working

My following code does not produce expected output:

public static void main(String[] args) throws MalformedURLException {

    Configuration.addDefaultResource("/home/some_user/conf.xml");
    Configuration conf = new Configuration();
    System.out.println(conf);
    System.out.println(conf.get("color"));
    assertThat(conf.get("color"), is("yellow"));
}

The property color is set in conf.xml file as follows:

<property>
        <name>color</name>
        <value>yellow</value>
        <description>Color</description>
</property>

Looks like file conf.xml isn't getting incorporated in default configuration.

The documentation for Configuration.addDefaultResource(String param) says the param should be in classpath. I don't understand how to add file to the classpath when I am already giving the program full absolute path.

Upvotes: 1

Views: 1094

Answers (1)

Razvan
Razvan

Reputation: 10093

First observation: I don't know which version of hadoop you use but the addDefaultResource() has been deprecated for a very long time.

In the later versions of Hadoop the standard way to accomplish what you want is:

Configuration conf = new Configuration()
conf.addResource("path/to/file");
...

Regarding the classpath issue, you have to simply place the config file in the classpath. So you have to discover what the classpath is to(it is either an environment var or the one which you set with -classpath option). If you didn't use the -classpath option and there is no classpath environment variable then it is automatically set to the current directory (".")

Upvotes: 2

Related Questions