Hadoop & Java: Connect Remote Unsecured HDFS

(Last Updated On: )

In this tutorial I will show you how to connect to remote unsecured HDFS cluster using Java. If you haven’t install hdfs yet follow the tutorial.

POM.xml:

  1. <dependency>
  2. <groupId>org.apache.hadoop</groupId>
  3. <artifactId>hadoop-client</artifactId>
  4. <version>2.9.1</version>
  5. </dependency>

Imports:

  1. import org.apache.hadoop.conf.Configuration;
  2. import org.apache.hadoop.fs.FileSystem;
  3. import java.net.URI;

Connect:

  1. //Setup the configuration object.
  2. final Configuration config = new Configuration();
  3.  
  4. //If you want you can add any properties you want here.
  5.  
  6. //Setup the hdfs file system object.
  7. final FileSystem fs = FileSystem.get(new URI("hdfs://localhost:50070"), config);
  8.  
  9. //Do whatever you need to.