New Contributor
Posts: 4
Registered: ‎05-14-2017

Java code to access Kerberized HDFS

Hi Experts,


I am unable to access Kerberized HDFS using Java code. Below is the code I am using. I have also tried various methods listed here.


package dao;

import org.apache.hadoop.conf.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.FileSystem;


public class WriteHDFSFile {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {
            Configuration config = new Configuration();
            config.set("fs.defaultFS", "hdfs://hdfs:8020");
            config.set("", "kerberos");
            UserGroupInformation.loginUserFromKeytab("usename@realm", "keytab file path in local compurter D drive");
            FileSystem dfs = FileSystem.get(config);
            Path src=new Path(dfs.getWorkingDirectory() + "<hdfs dir>/file2.txt");
        } catch (Exception e) {


With above code I am getting below error:


log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See for more info. Login failure for <username>@<realm> from keytab D:\abc.keytab: Unable to obtain password from user

    at dao.WriteHDFSFile.main(
Caused by: Unable to obtain password from user

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at Method)
    ... 1 more


Thanks in advance,