package org.myorg;
import java.security.PrivilegedExceptionAction;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileStatus;
public class Write{
public static void main(String args[]) {
try {
UserGroupInformation ugi = UserGroupInformation.createRemoteUser("hbase");
ugi.doAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://10.236.173.95:8020/user/hbase");
conf.set("hadoop.job.ugi", "hbase");
FileSystem fs = FileSystem.get(conf);
fs.createNewFile(new Path("/user/hbase/test"));
System.out.println("File Created");
return null;
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
这是我的java程序。我从this site下载了我的jar。我可以看到UserGroupInformation类在那里。我检查过createRemoteUser方法是这个类的成员。
我使用
编译这个程序 javac -classpath hadoop-0.20.1-dev-core.jar -d Write/ Write.java
我的目录结构包含
jarfile WriteDirectory Write.java
我收到以下错误
Write.java:16: error: cannot find symbol
UserGroupInformation ugi = UserGroupInformation.createRemoteUser("hbase");
^
symbol: method createRemoteUser(String)
location: class UserGroupInformation
Write.java:18: error: cannot find symbol
ugi.doAs(new PrivilegedExceptionAction<Void>() {
^
symbol: method doAs(<anonymous PrivilegedExceptionAction<Void>>)
location: variable ugi of type UserGroupInformation
2 errors
可能是什么原因?
答案 0 :(得分:2)
问题是您正在编译的Hadoop版本。你正在编译hadoop-0.20.1-dev-core.jar。我刚刚下载了它,javap
显示了UserGroupInformation类的以下内容:
public abstract class org.apache.hadoop.security.UserGroupInformation implements org.apache.hadoop.io.Writable,java.security.Principal {
public static final org.apache.commons.logging.Log LOG;
public org.apache.hadoop.security.UserGroupInformation();
public static org.apache.hadoop.security.UserGroupInformation getCurrentUGI();
public static void setCurrentUGI(org.apache.hadoop.security.UserGroupInformation);
static javax.security.auth.Subject getCurrentUser();
public static void setCurrentUser(org.apache.hadoop.security.UserGroupInformation);
public abstract java.lang.String getUserName();
public abstract java.lang.String[] getGroupNames();
public static org.apache.hadoop.security.UserGroupInformation login(org.apache.hadoop.conf.Configuration) throws javax.security.auth.login.LoginException;
public static org.apache.hadoop.security.UserGroupInformation readFrom(org.apache.hadoop.conf.Configuration) throws java.io.IOException;
static {};
}
没有迹象表明你要打电话的方法。
看起来你应该下载更新版本的Hadoop。 (我建议你替换Hadoop的整个,而不仅仅是一个jar文件。我没有做任何Hadoop开发,所以我不知道涉及多少个jar文件。)