zookeeper error

2019-03-18 431 words 3 mins read

Zookeeper报错 JAVA_HOME is not set

翻译:JAVA_HOME 变量没有设定

zkService 启动的时候,到底做了些什么?

1. 启动加载zkEvn文件
2. 启动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.

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="C:\Program Files\Java\jdk1.7.0_80\bin\java"
set JAVA_HOME="C:\Program Files\Java\jdk1.7.0_80"

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
)


再次启动,成功了!

该问题其实就是让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="C:\Program Files\Java\jdk1.7.0_80\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
)

启动时提示不是内部或外部命令,也不是可运行的程序

解决方法: 路径中间有空格,导致了该路径被作为一条命令被执行了,解决方法是给路径加上双引号

set JAVA=“C:\Program Files\Java\jdk1.7.0_80\bin\java”

至此解决Zookeeper安装后启动报错问题!


Tags: zookeeper

Related Articles:


author

Authored By WUHAOTIAN

A gentleman should always strive to improve himself

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it