java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.

hadoop null\bin\winutils.exe

原因1:hadoop 运行需要window系统编译过的软件,这个winutils.exe 可以在gtiee
或者github 上直接搜索到编译好的,找到后找到对应的版本下载,替换在本机上的 Hadoop
安装目录下 bin 下边的所以文件就可以了

原因2:Hadoop 在运行时会找到 hadoop_home_dir 和 HADOP_HOME 这两个环境变量
找到源码:重这里看出,要么设置HADOOP_HOME(系统变量)
要么设置hadoop_home_dir (临时变量)

/**
* 包:org.apache.hadoop.util
* 类: Shell
* 方法:checkHadoopHome
* 调用方:328 行:private static String HADOOP_HOME_DIR = checkHadoopHome();
*/

private static String checkHadoopHome() {

	// 在这里会找到 jvm 设置的环境变量 hadoop_home_dir
    // first check the Dflag hadoop.home.dir with JVM scope
    String home = System.getProperty("hadoop.home.dir");

    // fall back to the system/user-global env variable
    if (home == null) {
      // 上面找不到的话 这里会找环境变量 HADOOP_HOME 
      home = System.getenv("HADOOP_HOME");
    }

    try {
    	// 这里会检测 抛出但实际情况不会看到这个错误,可能被处理了
       // couldn't find either setting for hadoop's home directory
       if (home == null) {
         throw new IOException("HADOOP_HOME or hadoop.home.dir are not set.");
       }

       if (home.startsWith("\"") && home.endsWith("\"")) {
         home = home.substring(1, home.length()-1);
       }

       // check that the home setting is actually a directory that exists
       File homedir = new File(home);
       if (!homedir.isAbsolute() || !homedir.exists() || !homedir.isDirectory()) {
         throw new IOException("Hadoop home directory " + homedir
           + " does not exist, is not a directory, or is not an absolute path.");
       }

       home = homedir.getCanonicalPath();

    } catch (IOException ioe) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Failed to detect a valid hadoop home directory", ioe);
      }
      home = null;
    }
    
    return home;
  }

注意,虽然上面问题解决,但是还是会出现问题

原因是:程序在运行检查文件代码是出现,找不到本地方法


/**
* 包:org.apache.hadoop.io.nativeio
* 类: NativeIO
* 调用方:org.apache.hadoop.fs.FileUtil 下的canRead 方法
*/

public static boolean access(String path, AccessRight desiredAccess)
throws IOException {
return access0(path, desiredAccess.accessRight());
}


解决:
1、把hadoop.dll 添加到window32下
2、改代码 (在driver 类中添加)


String library = System.getProperty("java.library.path") + ";"+hadoopHome + "/bin";

System.setProperty("java.library.path",library);

Field sysPathsField;

// 主要代码,需要让这个配置生效
try {

    sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
    sysPathsField.setAccessible(true);
    try {
    	// 重要代码
        sysPathsField.set(null, null);
     } catch (IllegalAccessException e) {
         e.printStackTrace();
     }
} catch (NoSuchFieldException e) {
    e.printStackTrace();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值