java连接hadoop报错
java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
原因查找
找到报错位置hadoop包中的xxx/Shell.java
public static final String getQualifiedBinPath(String executable)
throws IOException {// construct hadoop bin path to the specified executableString fullExeName = HADOOP_HOME_DIR + File.separator + "bin" + File.separator + executable;File exeFile = new File(fullExeName);if (!exeFile.exists()) {throw new IOException("Could not locate executable " + fullExeName+ " in the Hadoop binaries.");}return exeFile.getCanonicalPath();
}
发现需要HADOOP_HOME_DIR变量
private static String HADOOP_HOME_DIR = checkHadoopHome();
private static String checkHadoopHome() {// first check the Dflag hadoop.home.dir with JVM scopeString home = System.getProperty("hadoop.home.dir");// fall back to the system/user-global env variableif (home == null) {home = System.getenv("HADOOP_HOME");}
……return home;
}
再次查找发现通过System.getProperty("hadoop.home.dir")或者环境变量HADOOP_HOME获取
故两种处理方式
1.直接设置属性System.setProperty("hadoop.home.dir", "D:\\Program\\hadoop-common-2.6.0-bin-master");
2.设置环境变量HADOOP_HOME
下载winutils地址https://github.com/srccodes/hadoop-common-2.2.0-bin下载解压
或者新版的https://github.com/amihalik/hadoop-common-2.6.0-bin
……感谢两位的编译
配置环境变量
增加用户变量HADOOP_HOME,值是下载的zip包解压的目录,然后在系统变量path里增加%HADOOP_HOME%\bin 即可。