不少開發者安裝zookeeper的時候,應該會發現到這麼一個問題: JAVA_HOME is not set html
好的!那麼這個是什麼意思呢?java
就是說你的 JAVA_HOME 變量沒有設定express
爲何會提示這個呢?apache
其實zookeeper在啓動服務端的時候會基於java環境啓動,因此在啓動的時候會檢測 jdk 是否安裝vim
而在咱們開發者的入門過程當中,都會設定一下 %JAVA_HOME%的系統變量。windows
在 zkservice啓動的時候,會找%JAVA_HOME%\bin\java.jar 進行java基礎環境的啓動。因此,若是沒有配置的話,就要配置:app
如何配置:區分兩種系統(自行百度吧)less
Linux: vim /etc/profile 文件修改後,檢查是否完成 java -versionui
window:變量添加後,檢查是否完成 java -versionthis
好的!按理說完成以上步驟以後,就是已經完成了%JAVA_HOME%的配置。
針對於window8 系統配置完成以後,使用 -version均可以發現正常進行了安裝,可是啓動的時候依舊報錯!JAVA_HOME is not set
這就不能忍了!因而咱們看看,zkService 啓動的時候,到底作了些什麼?
一、啓動加載zkEvn文件,
二、啓動zkService文件,
也就是說,在zkEvn 文件裏面可能有JAVA_HOME 的驗證,因而咱們進去看看
@echo off REM Licensed to the Apache Software Foundation (ASF) under one or more REM contributor license agreements. See the NOTICE file distributed with REM this work for additional information regarding copyright ownership. REM The ASF licenses this file to You under the Apache License, Version 2.0 REM (the "License"); you may not use this file except in compliance with REM the License. You may obtain a copy of the License at REM REM http://www.apache.org/licenses/LICENSE-2.0 REM REM Unless required by applicable law or agreed to in writing, software REM distributed under the License is distributed on an "AS IS" BASIS, REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. REM See the License for the specific language governing permissions and REM limitations under the License. set ZOOCFGDIR=%~dp0%..\conf set ZOO_LOG_DIR=%~dp0%..\logs set ZOO_LOG4J_PROP=INFO,CONSOLE REM for sanity sake assume Java 1.6 REM see: http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html REM add the zoocfg dir to classpath set CLASSPATH=%ZOOCFGDIR% REM make it work in the release SET CLASSPATH=%~dp0..\*;%~dp0..\lib\*;%CLASSPATH% REM make it work for developers SET CLASSPATH=%~dp0..\build\classes;%~dp0..\build\lib\*;%CLASSPATH% set ZOOCFG=%ZOOCFGDIR%\zoo.cfg @REM setup java environment variables if not defined JAVA_HOME ( echo Error: JAVA_HOME is not set. goto :eof ) if not exist %JAVA_HOME%\bin\java.exe ( echo Error: JAVA_HOME is incorrectly set. goto :eof ) set JAVA=%JAVA_HOME%\bin\java
果真!這裏有校驗!並且校驗的時候確定是不存在的,因此輸出錯誤信息:JAVA_HOME is not set.
那麼如何解決呢?
既然從系統變量獲取獲取不到這個變量,那麼咱們乾脆手動設置一下試試?
@echo off REM Licensed to the Apache Software Foundation (ASF) under one or more REM contributor license agreements. See the NOTICE file distributed with REM this work for additional information regarding copyright ownership. REM The ASF licenses this file to You under the Apache License, Version 2.0 REM (the "License"); you may not use this file except in compliance with REM the License. You may obtain a copy of the License at REM REM http://www.apache.org/licenses/LICENSE-2.0 REM REM Unless required by applicable law or agreed to in writing, software REM distributed under the License is distributed on an "AS IS" BASIS, REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. REM See the License for the specific language governing permissions and REM limitations under the License. REM for sanity sake assume Java 1.6 REM see: http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html REM add the zoocfg dir to classpath set CLASSPATH=%ZOOCFGDIR% REM make it work in the release SET CLASSPATH=%~dp0..\*;%~dp0..\lib\*;%CLASSPATH% REM make it work for developers SET CLASSPATH=%~dp0..\build\classes;%~dp0..\build\lib\*;%CLASSPATH% set JAVA=D:\java\jdk1.8.0_77\bin\java set JAVA_HOME=D:\java\jdk1.8.0_77 set ZOOCFG=%ZOOCFGDIR%\zoo.cfg set ZOOCFGDIR=%~dp0%..\conf set ZOO_LOG_DIR=%~dp0%..\logs set ZOO_LOG4J_PROP=INFO,CONSOLE @REM setup java environment variables if not defined JAVA_HOME ( echo Error: JAVA_HOME is not set. goto :eof ) if not defined JAVA ( echo Error: ----"%JAVA_HOME%"--- is set.but not found JAVA goto :eof )
修改內容如上:
手動設置JAVAHOME 和JAVA 的值,爲了查找問題,在判斷JAVA的時候,進行JAVAHOME 的值的打印,看看是否是真的設置成功了。
再次啓動,果真!成功了!
好的,我們回顧一下。zkService 啓動依賴java的環境,因此必需要可以啓動java環境,對應的就是 JDK 安裝目錄下\bin\java.exe 須要被啓動。
因此我們要告訴JAVA的值
也就是設置:
set JAVA=D:\java\jdk1.8.0_77\bin\java (D:\java\jdk1.8.0_77 這裏是你的JDK安裝路徑)
再思考一點,我們設定
set JAVA_HOME=D:\java\jdk1.8.0_77
目的其實就是讓JAVA可以使用JAVA_HOME的變量的值,因此,既然我們都手動設定了JAVA的絕對路徑,那麼其實JAVA_HOME 的設置和判斷均可以去掉了。
對應簡化內容爲:
@echo off REM Licensed to the Apache Software Foundation (ASF) under one or more REM contributor license agreements. See the NOTICE file distributed with REM this work for additional information regarding copyright ownership. REM The ASF licenses this file to You under the Apache License, Version 2.0 REM (the "License"); you may not use this file except in compliance with REM the License. You may obtain a copy of the License at REM REM http://www.apache.org/licenses/LICENSE-2.0 REM REM Unless required by applicable law or agreed to in writing, software REM distributed under the License is distributed on an "AS IS" BASIS, REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. REM See the License for the specific language governing permissions and REM limitations under the License. REM for sanity sake assume Java 1.6 REM see: http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html REM add the zoocfg dir to classpath set CLASSPATH=%ZOOCFGDIR% REM make it work in the release SET CLASSPATH=%~dp0..\*;%~dp0..\lib\*;%CLASSPATH% REM make it work for developers SET CLASSPATH=%~dp0..\build\classes;%~dp0..\build\lib\*;%CLASSPATH% set JAVA=D:\java\jdk1.8.0_77\bin\java set ZOOCFG=%ZOOCFGDIR%\zoo.cfg set ZOOCFGDIR=%~dp0%..\conf set ZOO_LOG_DIR=%~dp0%..\logs set ZOO_LOG4J_PROP=INFO,CONSOLE @REM setup java environment variables if not defined JAVA ( echo Error: not found JAVA goto :eof )
總結:這種狀況目前只出如今window 8 的系統上,推測window 10 可能也會存在。可是在Linux的環境下,沒遇到過。你們能夠手動試試,並讀懂執行代碼,就能夠本身修改和編寫了。感謝看官,若是有疑問你們一塊兒討論,關注或者留言。