之前在mac上调试hadoop程序(mac之前配置过hadoop环境)一直都是正常的。因为工作需要,需要在windows上先调试该程序,然后再转到linux下。程序运行的过程中,报 Failed to locate the winutils binary in the hadoop binary path   java.io.IOException: Could not locate executable null \bin\winutils.exe in the Hadoop binaries.

通过断点调试、查看源码发现程序需要根据HADOOP_HOME找到winutils.exe,由于win机器并没有配置该环境变量,所以程序报 null\bin\winutils.exe。

  1. private static String checkHadoopHome() {
  2. // first check the Dflag hadoop.home.dir with JVM scope
  3. String home = System.getProperty("hadoop.home.dir");
  4.  
  5. // fall back to the system/user-global env variable
  6. if (home == null) {
  7. home = System.getenv("HADOOP_HOME");
  8. }
  9. try {
  10. // couldn't find either setting for hadoop's home directory
  11. if (home == null) {
  12. throw new IOException("HADOOP_HOME or hadoop.home.dir are not set.");
  13. }
  14. if (home.startsWith("\"") && home.endsWith("\"")) {
  15. home = home.substring(1, home.length()-1);
  16. }
  17. // check that the home setting is actually a directory that exists
  18. File homedir = new File(home);
  19. if (!homedir.isAbsolute() || !homedir.exists() || !homedir.isDirectory()) {
  20. throw new IOException("Hadoop home directory " + homedir
  21. + " does not exist, is not a directory, or is not an absolute path.");
  22. }
  23. home = homedir.getCanonicalPath();
  24. } catch (IOException ioe) {
  25. if (LOG.isDebugEnabled()) {
  26. LOG.debug("Failed to detect a valid hadoop home directory", ioe);
  27. }
  28. home = null;
  29. }
  30. return home;
  31. }

private static String HADOOP_HOME_DIR = checkHadoopHome ();

  1. public static final String getQualifiedBinPath(String executable)
  2. throws IOException {
  3. // construct hadoop bin path to the specified executable
  4. String fullExeName = HADOOP_HOME_DIR + File.separator + "bin"
  5. + File.separator + executable;
  6.  
  7. File exeFile = new File(fullExeName);
  8. if (!exeFile.exists()) {
  9. throw new IOException("Could not locate executable " + fullExeName
  10. + " in the Hadoop binaries.");
  11. }
  12. return exeFile.getCanonicalPath();
  13. }
  14.  
  15. /** a Windows utility to emulate Unix commands */
  16. public static final String WINUTILS = getWinUtilsPath();
  17.  
  18. public static final String getWinUtilsPath() {
  19. String winUtilsPath = null;
  20.  
  21. try {
  22. if (WINDOWS) {
  23. winUtilsPath = getQualifiedBinPath("winutils.exe");
  24. }
  25. } catch (IOException ioe) {
  26. LOG.error("Failed to locate the winutils binary in the hadoop binary path",
  27. ioe);
  28. }
  29.  
  30. return winUtilsPath;
  31. }

找到原因后就去网上问了度娘,找到了解决方案,很简单,如下:

1.下载winutils的windows版本

GitHub上,有人提供了winutils的windows的版本,项目地址是: https://github.com/srccodes/hadoop-common-2.2.0-bin ,直接下载此项目的zip包,下载后是文件名是hadoop-common-2.2.0-bin-master.zip,随便解压到一个目录

2.配置环境变量

增加用户变量HADOOP_HOME,值是下载的zip包解压的目录,然后在系统变量path里增加$HADOOP_HOME\bin 即可。

再次运行程序,正常执行。

Spark报错:Failed to locate the winutils binary in the hadoop binary path的更多相关文章

  1. WIN7下运行hadoop程序报:Failed to locate the winutils binary in the hadoop binary path

    之前在mac上调试hadoop程序(mac之前配置过hadoop环境)一直都是正常的.因为工作需要,需要在windows上先调试该程序,然后再转到linux下.程序运行的过程中,报Failed to ...

  2. 解决spark运行中failed to locate the winutils binary in the hadoop binary path的问题

    1.下载hadoop-common-2.2.0-bin并解压到某个目录 https://github.com/srccodes/hadoop-common-2.2.0-bin 2.设置hadoop.h ...

  3. Windows本地运行调试Spark或Hadoop程序失败:ERROR util.Shell: Failed to locate the winutils binary in the hadoop binary path

    报错内容 ERROR util.Shell: Failed to locate the winutils binary in the hadoop binary path java.io.IOExce ...

  4. Hadoop:开发机运行spark程序,抛出异常:ERROR Shell: Failed to locate the winutils binary in the hadoop binary path

    问题: windows开发机运行spark程序,抛出异常:ERROR Shell: Failed to locate the winutils binary in the hadoop binary ...

  5. Windows7系统运行hadoop报Failed to locate the winutils binary in the hadoop binary path错误

    程序运行的过程中,报Failed to locate the winutils binary in the hadoop binary path  Java.io.IOException: Could ...

  6. Spark- ERROR Shell: Failed to locate the winutils binary in the hadoop binary path java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.

    运行 mport org.apache.log4j.{Level, Logger} import org.apache.spark.rdd.RDD import org.apache.spark.{S ...

  7. windows本地调试安装hadoop(idea) : ERROR util.Shell: Failed to locate the winutils binary in the hadoop binary path

    1,本地安装hadoop https://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/ 下载hadoop对应版本 (我本意是想下载hadoop ...

  8. ERROR Shell: Failed to locate the winutils binary in the hadoop binary path

    文章发自:http://www.cnblogs.com/hark0623/p/4170172.html  转发请注明 14/12/17 19:18:53 ERROR Shell: Failed to ...

  9. spark报错处理

    Spark报错处理 1.问题:org.apache.spark.SparkException: Exception thrown in awaitResult 分析:出现这个情况的原因是spark启动 ...

随机推荐

  1. HDU 2276 矩阵快速幂

    Kiki & Little Kiki 2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  2. Java HashMap的工作原理

    面试的时候经常会遇见诸如:”java中的HashMap是怎么工作的”.”HashMap的get和put内部的工作原理”这样的问题. 本文将用一个简单的例子来解释下HashMap内部的工作原理. 首先我 ...

  3. 004——php字符串中处理函数(三)

    <?php /** * 字符串替换函数: * str_replace(); 替换字符串或数组元素,区分大小写,第四个参数可选,用于统计替换次数 * str_ireplace()不区分大小写替换 ...

  4. Win7操作系统安装IE10提示“安装前需要更新与安装程序版本”

    安装IE10浏览器时提示错误的 Internet Explorer安装程序版本 故障现象: Win7操作系统在安装IE10浏览器时会弹出对话框,提示错误的Ieternet Explorer 安装程序版 ...

  5. Kotlin Reference (十) Interfaces

    most from reference 接口 Kotlin中的接口非常类似于Java8,它们可以包含抽象方法的声明以及方法实现.与抽象类不同的是接口不能存储状态.它们可以具有属性,但这些需要是抽象的或 ...

  6. LTIB for ubuntu12.04

     在 ltib 目录中执行以下代码: cd <your ltib folder>./patch-ltib-ubuntu12.04.shpatch -p1 < patch-dist-u ...

  7. StringUtils的工具类isBlank与isEmply

    1. public static boolean isEmpty(String str)   判断某字符串是否为空,为空的标准是 str==null 或 str.length()==0   下面是 S ...

  8. SimpleDateFormat格式化日期以及日期的相关操作

    一.Java中的日期概述   日期在Java中是一块非常复杂的内容,对于一个日期在不同的语言国别环境中,日期的国际化,日期和时间之间的转换,日期的加减运算,日期的展示格式都是非常复杂的问题.   在J ...

  9. 我的AOP那点事儿--1

    题记:一段时间以来一直想整理下关于AOP的知识,之前一直停留在会怎么使用AOP,关于AOP的深入点儿的知识就不知所以然了,正好项目上刚好用到需要用AOP实现的功能,所以找个时间统一整理下就很有必要了. ...

  10. vmware克隆linux网络配置

    一.配置Linux网络 在安装Linux的时候,一定要保证你的物理网络的IP是手动设置的,要不然会在Linux设置IP连通网络的时候会报network is unreachable 并且怎么也找不到问 ...