org.apache.hadoop.security.usergroupinformation安全异常错误

4sup72z8  于 2021-05-29  发布在  Hadoop
关注(0)|答案(0)|浏览(784)

嗨,我试图创建一个文件在hdfs从java程序。但我得到了安全异常

java.lang.NoClassDefFoundError: Could not initialize class org.apache.hadoop.security.UserGroupInformation
at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:2806)
at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:2798)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2661)

我的java代码。

Configuration conf = new Configuration();
conf.set("fs.hdfs.impl",
org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
conf.set("fs.file.impl",
org.apache.hadoop.fs.LocalFileSystem.class.getName());
conf.addResource(new Path("/etc/hadoop/conf/core-site.xml"));
conf.addResource(new Path("/etc/hadoop/conf/hdfs-site.xml"));
BufferedWriter br = null;
FileSystem hdfs = null;
  try {
java.util.Date date = new java.util.Date();
hdfs = FileSystem.get(new URI("hdfs://aserver:8020"), conf);
Path file = new Path(
"hdfs://aserver:8020/user/ec2-user/AddressInformation/"
+ date.getTime());
OutputStream os = hdfs.create(file);
br = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
br.write(result);
br.close();
hdfs.close();
return result;
}
catch (Exception e) { return "error"; } 
} }

任何帮助都将不胜感激。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题