1. 程式人生 > >Java開發HBase程式報錯:HADOOP_HOME or hadoop.home.dir are not set.

Java開發HBase程式報錯:HADOOP_HOME or hadoop.home.dir are not set.

Java開發HBase程式報錯:HADOOP_HOME or hadoop.home.dir are not set.

1.報錯

16:36:44.271 [main] DEBUG org.apache.hadoop.util.Shell - Failed to detect a valid hadoop home directory
java.io.IOException: HADOOP_HOME or hadoop.home.dir are not set.
	at org.apache.hadoop.util.Shell.checkHadoopHome(Shell.java:
302) [hadoop-common-2.6.4.jar:na] at org.apache.hadoop.util.Shell.<clinit>(Shell.java:327) [hadoop-common-2.6.4.jar:na] at org.apache.hadoop.util.StringUtils.<clinit>(StringUtils.java:79) [hadoop-common-2.6.4.jar:na] at org.apache.hadoop.security.Groups.parseStaticMapping(Groups.java:116
) [hadoop-common-2.6.4.jar:na] at org.apache.hadoop.security.Groups.<init>(Groups.java:93) [hadoop-common-2.6.4.jar:na] at org.apache.hadoop.security.Groups.<init>(Groups.java:73) [hadoop-common-2.6.4.jar:na] at org.apache.hadoop.security.Groups.getUserToGroupsMappingService(Groups.java:
293) [hadoop-common-2.6.4.jar:na] at org.apache.hadoop.security.Groups.getUserToGroupsMappingService(Groups.java:278) [hadoop-common-2.6.4.jar:na] at org.apache.hadoop.hbase.security.UserProvider.<clinit>(UserProvider.java:56) [hbase-common-1.4.0.jar:1.4.0] at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:214) [hbase-client-1.4.0.jar:1.4.0] at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:119) [hbase-client-1.4.0.jar:1.4.0] at utils.HBaseUtils.<clinit>(HBaseUtils.java:26) [classes/:na] at Test.HBaseTest.main(HBaseTest.java:12) [classes/:na] 16:36:44.272 [main] ERROR org.apache.hadoop.util.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. at org.apache.hadoop.util.Shell.getQualifiedBinPath(Shell.java:355) [hadoop-common-2.6.4.jar:na] at org.apache.hadoop.util.Shell.getWinUtilsPath(Shell.java:370) [hadoop-common-2.6.4.jar:na] at org.apache.hadoop.util.Shell.<clinit>(Shell.java:363) [hadoop-common-2.6.4.jar:na] at org.apache.hadoop.util.StringUtils.<clinit>(StringUtils.java:79) [hadoop-common-2.6.4.jar:na] at org.apache.hadoop.security.Groups.parseStaticMapping(Groups.java:116) [hadoop-common-2.6.4.jar:na] at org.apache.hadoop.security.Groups.<init>(Groups.java:93) [hadoop-common-2.6.4.jar:na] at org.apache.hadoop.security.Groups.<init>(Groups.java:73) [hadoop-common-2.6.4.jar:na] at org.apache.hadoop.security.Groups.getUserToGroupsMappingService(Groups.java:293) [hadoop-common-2.6.4.jar:na] at org.apache.hadoop.security.Groups.getUserToGroupsMappingService(Groups.java:278) [hadoop-common-2.6.4.jar:na] at org.apache.hadoop.hbase.security.UserProvider.<clinit>(UserProvider.java:56) [hbase-common-1.4.0.jar:1.4.0] at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:214) [hbase-client-1.4.0.jar:1.4.0] at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:119) [hbase-client-1.4.0.jar:1.4.0] at utils.HBaseUtils.<clinit>(HBaseUtils.java:26) [classes/:na] at Test.HBaseTest.main(HBaseTest.java:12) [classes/:na]

2.解決辦法

  • step1:下載winutils.exe包,連結地址:https://github.com/srccodes/hadoop-common-2.2.0-bin 。然後將其放到hadoop的包(意思就是說,windows中需要解壓hadoop的安裝包)的bin目錄下。
  • step2:在程式起始處新增語句:System.setProperty("hadoop.home.dir", "D:\\SoftWarePackages\\BigData\\hadoop-2.6.4");

參考文章