Find Hadoop Configuration in Java Util

0 votes

I am planning to write a Java Util that should be accessing HDFS. I have a requirement for a configuration Object

Configuration conf = new Configuration()

I had used the above code to create one. This method was unsuccessful and threw out the following info.

fs.getHomeDirectory() 

I have even tried to make some changes in 

  • Core-site.xml
  • mapred-site.xml
  • yarn-site.xml
  • hfds-site.xml

None of the modifications helped out.

please help me resovle this issue.

Jun 17, 2019 in Big Data Hadoop by nitinrawat895
• 11,380 points
1,231 views

1 answer to this question.

0 votes

I understand your issue of HDFS, I feel your Core-Site.xml and HDFS-site.xml are not correctly assigned.

This following code must help you.

Configuration conf = new Configuration();
conf.addResource(new Path("file:///etc/hadoop/conf/core-site.xml")); // Replace with actual path
conf.addResource(new Path("file:///etc/hadoop/conf/hdfs-site.xml")); // Replace with actual path

Path pt = new Path("."); // HDFS Path
FileSystem fs = pt.getFileSystem(conf);

System.out.println("Home directory :"+fs.getHomeDirectory());

This should help, Even then if you face the same trouble, Then try adding the configuration files using addResource method. Use set method instead of add method in the value fs.defaultFS in your core-site.xml

conf.set("fs.defaultFS","hdfs://<Namenode-Host>:<Port>");  // Refer you core-site.xml file and replace <Namenode-Host> and <Port> with your cluster namenode and Port (default port number should be `8020`). 
answered Jun 17, 2019 by ravikiran
• 4,620 points

Related Questions In Big Data Hadoop

0 votes
1 answer

Is there any way to increase Java Heap size in Hadoop?

You can add some more memory by ...READ MORE

answered Apr 12, 2018 in Big Data Hadoop by nitinrawat895
• 11,380 points
4,967 views
0 votes
1 answer

Why Java Code in Hadoop uses own Data Types instead of basic Data types?

Hadoop provides us Writable interface based data ...READ MORE

answered Apr 15, 2018 in Big Data Hadoop by kurt_cobain
• 9,350 points
1,165 views
0 votes
1 answer

can't find start-all.sh in hadoop installation

Actually, you are not mentioning the path for ...READ MORE

answered Apr 17, 2018 in Big Data Hadoop by nitinrawat895
• 11,380 points
8,290 views
0 votes
1 answer

How to find Hadoop version in CDH?

The simplest way to check Hadoop version ...READ MORE

answered Apr 19, 2018 in Big Data Hadoop by nitinrawat895
• 11,380 points
9,015 views
0 votes
1 answer

Moving files in Hadoop using the Java API?

I would recommend you to use FileSystem.rename(). ...READ MORE

answered Apr 15, 2018 in Big Data Hadoop by Shubham
• 13,490 points
2,674 views
0 votes
1 answer

Hadoop giving java.io.IOException, in mkdir Java code.

I am not sure about the issue. ...READ MORE

answered May 3, 2018 in Big Data Hadoop by Shubham
• 13,490 points
2,547 views
+1 vote
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 11,380 points
11,034 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 11,380 points
2,540 views
0 votes
1 answer

Explain to me how to get Hadoop configuration in Java Util.

In order to get access to the File ...READ MORE

answered May 24, 2019 in Big Data Hadoop by ravikiran
• 4,620 points
2,194 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP