很多开发者安装zookeeper的时候,应该会发现到这么一个问题: JAVA_HOME is not set

好的!那么这个是什么意思呢?

就是说你的  JAVA_HOME 变量没有设定

为什么会提示这个呢?

其实zookeeper在启动服务端的时候会基于java环境启动,所以在启动的时候会检测 jdk 是否安装

而在我们开发者的入门过程中,都会设定一下 %JAVA_HOME%的系统变量。

在 zkservice启动的时候,会找%JAVA_HOME%\bin\java.jar 进行java基础环境的启动。所以,如果没有配置的话,就要配置:

如何配置:区分两种系统(自行百度吧)

  Linux: vim /etc/profile 文件修改后,检查是否完成 java  -version

  window:变量添加后,检查是否完成 java -version

好的!按理说完成以上步骤之后,就是已经完成了%JAVA_HOME%的配置。

针对于window8 系统配置完成之后,使用 -version都可以发现正常进行了安装,但是启动的时候依旧报错!JAVA_HOME is not set

这就不能忍了!于是我们看看,zkService 启动的时候,到底做了些什么?

  1、启动加载zkEvn文件,

  2、启动zkService文件,

也就是说,在zkEvn 文件里面可能有JAVA_HOME 的验证,于是我们进去看看

  1. @echo off
  2. REM Licensed to the Apache Software Foundation (ASF) under one or more
  3. REM contributor license agreements. See the NOTICE file distributed with
  4. REM this work for additional information regarding copyright ownership.
  5. REM The ASF licenses this file to You under the Apache License, Version 2.0
  6. REM (the "License"); you may not use this file except in compliance with
  7. REM the License. You may obtain a copy of the License at
  8. REM
  9. REM http://www.apache.org/licenses/LICENSE-2.0
  10. REM
  11. REM Unless required by applicable law or agreed to in writing, software
  12. REM distributed under the License is distributed on an "AS IS" BASIS,
  13. REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. REM See the License for the specific language governing permissions and
  15. REM limitations under the License.
  16.  
  17. set ZOOCFGDIR=%~dp0%..\conf
  18. set ZOO_LOG_DIR=%~dp0%..\logs
  19. set ZOO_LOG4J_PROP=INFO,CONSOLE
  20.  
  21. REM for sanity sake assume Java 1.6
  22. REM see: http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html
  23.  
  24. REM add the zoocfg dir to classpath
  25. set CLASSPATH=%ZOOCFGDIR%
  26.  
  27. REM make it work in the release
  28. SET CLASSPATH=%~dp0..\*;%~dp0..\lib\*;%CLASSPATH%
  29.  
  30. REM make it work for developers
  31. SET CLASSPATH=%~dp0..\build\classes;%~dp0..\build\lib\*;%CLASSPATH%
  32.  
  33. set ZOOCFG=%ZOOCFGDIR%\zoo.cfg
  34.  
  35. @REM setup java environment variables

  36. if not defined JAVA_HOME (
  37. echo Error: JAVA_HOME is not set.
  38. goto :eof
  39. )
  40. if not exist %JAVA_HOME%\bin\java.exe (
  41. echo Error: JAVA_HOME is incorrectly set.
  42. goto :eof
  43. )
  44.  
  45. set JAVA=%JAVA_HOME%\bin\java

果然!这里有校验!而且校验的时候肯定是不存在的,所以输出错误信息:JAVA_HOME is not set.

那么如何解决呢?

既然从系统变量获取获取不到这个变量,那么我们干脆手动设置一下试试?

  1. @echo off
  2. REM Licensed to the Apache Software Foundation (ASF) under one or more
  3. REM contributor license agreements. See the NOTICE file distributed with
  4. REM this work for additional information regarding copyright ownership.
  5. REM The ASF licenses this file to You under the Apache License, Version 2.0
  6. REM (the "License"); you may not use this file except in compliance with
  7. REM the License. You may obtain a copy of the License at
  8. REM
  9. REM http://www.apache.org/licenses/LICENSE-2.0
  10. REM
  11. REM Unless required by applicable law or agreed to in writing, software
  12. REM distributed under the License is distributed on an "AS IS" BASIS,
  13. REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. REM See the License for the specific language governing permissions and
  15. REM limitations under the License.
  16.  
  17. REM for sanity sake assume Java 1.6
  18. REM see: http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html
  19.  
  20. REM add the zoocfg dir to classpath
  21. set CLASSPATH=%ZOOCFGDIR%
  22.  
  23. REM make it work in the release
  24. SET CLASSPATH=%~dp0..\*;%~dp0..\lib\*;%CLASSPATH%
  25.  
  26. REM make it work for developers
  27. SET CLASSPATH=%~dp0..\build\classes;%~dp0..\build\lib\*;%CLASSPATH%
  28.  
  29. set JAVA=D:\java\jdk1.8.0_77\bin\java
  30. set JAVA_HOME=D:\java\jdk1.8.0_77

  31. set ZOOCFG=%ZOOCFGDIR%\zoo.cfg
  32. set ZOOCFGDIR=%~dp0%..\conf
  33. set ZOO_LOG_DIR=%~dp0%..\logs
  34. set ZOO_LOG4J_PROP=INFO,CONSOLE
  35. @REM setup java environment variables
  36.  
  37. if not defined JAVA_HOME (
  38. echo Error: JAVA_HOME is not set.
  39. goto :eof
  40. )
  41.  
  42. if not defined JAVA (
  43. echo Error: ----"%JAVA_HOME%"--- is set.but not found JAVA
  44. goto :eof
  45. )

修改内容如上:

手动设置JAVAHOME 和JAVA 的值,为了查找问题,在判断JAVA的时候,进行JAVAHOME 的值的打印,看看是不是真的设置成功了。

再次启动,果然!成功了!

好的,咱们回顾一下。zkService 启动依赖java的环境,所以必须要能够启动java环境,对应的就是 JDK 安装目录下\bin\java.exe 需要被启动。

所以咱们要告诉JAVA的值

也就是设置:

  1. set JAVA=D:\java\jdk1.8.0_77\bin\java D:\java\jdk1.8.0_77 这里是你的JDK安装路径
    再思考一点,咱们设定
  1. set JAVA_HOME=D:\java\jdk1.8.0_77
    目的其实就是让JAVA能够使用JAVA_HOME的变量的值,所以,既然咱们都手动设定了JAVA的绝对路径,那么其实JAVA_HOME 的设置和判断都可以去掉了。
    对应简化内容为:
  1. @echo off
  2. REM Licensed to the Apache Software Foundation (ASF) under one or more
  3. REM contributor license agreements. See the NOTICE file distributed with
  4. REM this work for additional information regarding copyright ownership.
  5. REM The ASF licenses this file to You under the Apache License, Version 2.0
  6. REM (the "License"); you may not use this file except in compliance with
  7. REM the License. You may obtain a copy of the License at
  8. REM
  9. REM http://www.apache.org/licenses/LICENSE-2.0
  10. REM
  11. REM Unless required by applicable law or agreed to in writing, software
  12. REM distributed under the License is distributed on an "AS IS" BASIS,
  13. REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. REM See the License for the specific language governing permissions and
  15. REM limitations under the License.
  16.  
  17. REM for sanity sake assume Java 1.6
  18. REM see: http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html
  19.  
  20. REM add the zoocfg dir to classpath
  21. set CLASSPATH=%ZOOCFGDIR%
  22.  
  23. REM make it work in the release
  24. SET CLASSPATH=%~dp0..\*;%~dp0..\lib\*;%CLASSPATH%
  25.  
  26. REM make it work for developers
  27. SET CLASSPATH=%~dp0..\build\classes;%~dp0..\build\lib\*;%CLASSPATH%
  28.  
  29. set JAVA=D:\java\jdk1.8.0_77\bin\java
  30. set ZOOCFG=%ZOOCFGDIR%\zoo.cfg
  31. set ZOOCFGDIR=%~dp0%..\conf
  32. set ZOO_LOG_DIR=%~dp0%..\logs
  33. set ZOO_LOG4J_PROP=INFO,CONSOLE
  34. @REM setup java environment variables
  35.  
  36. if not defined JAVA (
  37. echo Error: not found JAVA
  38. goto :eof
  39. )
  1. 总结:这种情况目前只出现在window 8 的系统上,推测window 10 可能也会存在。但是在Linux的环境下,没遇到过。大家可以手动试试,并读懂执行代码,就可以自己修改和编写了。
    感谢看官,如果有疑问大家一起讨论,关注或者留言。
  1.  

zookeeper报错 JAVA_HOME is not set的更多相关文章

  1. 启动zookeeper报错:JAVA_HOME is not set

    启动zookeeper时报错JAVA_HOME is not set 看了环境变量,确实配置好了,但是zookeeper竟然没找到 修改bin目录下的zkEnv.cmd关于jdk的一部分 set JA ...

  2. zookeeper报错java.net.ConnectException: Connection refused: no further information

    zookeeper报错java.net.ConnectException: Connection refused: no further information 这是在linux 启动 https:/ ...

  3. zookeeper报错: org.I0Itec.zkclient.exception.ZkMarshallingError: java.io.EOFException

    zookeeper报错: org.I0Itec.zkclient.exception.ZkMarshallingError: java.io.EOFException 主要因为是没有序列化. 可以使用 ...

  4. 解决zookeeper报错[NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@362] - Exception causing close

    zookeeper.out报错: 2016-12-10 18:05:46,958 [myid:3] - WARN  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181 ...

  5. maven 配置报错 JAVA_HOME not found in your environment

    最近比较空,想研究下spring mvc,于是编按照教程一步一步配置开发环境.配置maven完成后,运行命令mvn -v的时候,竟然报错.错误信息如下: Error: JAVA_HOME not fo ...

  6. Kafka自带zookeeper报错INFO Got user-level KeeperException when processing xxx Error Path:/brokers Error:KeeperErrorCode = NodeExists for /brokers (org.apache.zookeeper.server.PrepRequestProcessor)

    问题描述: 按照kafka官方文档的操作步骤,解压kafka压缩包后.依次启动zookeeper,和kafka服务 kafka服务启动后,查看到zookeeper日志里有以下异常 问题原因及解决办法: ...

  7. 使用zookeeper报错 stat is not executed because it is not in the whitelist. envi is not executed because it is not in the whitelist.

    在使用四字命令或者zk ui界面查看zookeeper集群时,出现如下提示: stat is not executed because it is not in the whitelist. envi ...

  8. ZooKeeper启动报错 JAVA_HOME is incorrectly set

    解决办法:在zkEnv.cmd文件中直接写死调用的jdk路径 set JAVA_HOME="D:\Program Files\Java7\jdk1.7.0_51" if not e ...

  9. hadoop start-all.sh报错JAVA_HOME is not set and could not be found.

    原文 错误:JAVA_HOME is not set and could not be found,可能是因为JAVA_HOME环境没配置正确,还有一种情况是即使各结点都正确地配置了JAVA_HOME ...

随机推荐

  1. 相比之前其他几个入门的, 推荐: 简单vue2 入门教程

    注意:Vue.js 不支持 IE8 及其以下 IE 版本.       具体可以看下  http://www.runoob.com/vue2/vue-tutorial.html 以下是学习过程 Vue ...

  2. Android学习笔记(1)----播放音乐文件

    原文地址:http://www.cnblogs.com/wynet/p/5526905.html 这里介绍两种播放资源文件的方法: 第一种. assets类资源放在工程根目录的assets子目录下,它 ...

  3. win10命令控制符

    IP:ipconfigIP地址侦测器:Nslookup显卡:dxdiag控制面板:control电话拨号:dialer木马捆绑工具,系统自带:iexpress本地用户和组:lusrmgr.msc鼠标属 ...

  4. 小程序UI

    从input组件说起 <input maxlength="10" placeholder="最大输入长度10" /> <div id=&quo ...

  5. margin的用法

    margin塌陷问题 当时说到了盒模型,盒模型包含着margin,为什么要在这里说margin呢?因为元素和元素在垂直方向上margin里面有坑. 我们来看一个例子: html结构: <div ...

  6. 第一课 PPT 所学内容总结

    制作PPT时要注意三要素即:图形,颜色搭配,字数适当. 感悟:制作一个好的PPT也并不需要华丽的画面.只需清晰的表达出自己想要表达的,就是一个好PPT.

  7. 在IIS上发布网站后,在编译时出现CS0016拒绝访问错误

    错误如下图所示:     关键性错误信息:   编译器错误消息: CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Te ...

  8. 使用ESP8266连接到Azure

    很多同学在问我,ESP8266如何连接到Azure,因为官方只有Spark Fun之类的DevKit(开发套件)出了教程(我只找到了套件的文档). 先上视频:http://v.youku.com/v_ ...

  9. Permission Denial: opening provider 隐藏的android:exported属性的含义

    Permission Denial: opening provider 隐藏的android:exported属性的含义 2013-03-07 13:17 227人阅读 评论(0) 收藏 举报 场景: ...

  10. POJ 2528 Mayor's poster

    主要是参考了这个博客 地址戳这儿 题目大意:n(n<=10000) 个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=10000000) .求出最后还能看 ...