问题描述:
TOMCAT JAVA_HOME or JRE_HOME environment variable is not defined correctly
报错信息如下:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program;提示找不到java_home各jre_home路径,何解?
原因不知道了,下面来看解决办法:
1、分析startup.bat启动脚本:发现其调用了catalina.bat,而catalina.bat调用了setclasspath.bat
2、在setclasspath.bat的头部定义了JAVA_HOME和JRE_HOME的值,那么在这里手动设置JAVA_HOME变量
@echo off
rem Licensed to the Apache Software Foundation (ASF) under one or morerem contributor license agreements. See the NOTICE file distributed withrem this work for additional information regarding copyright ownership.rem The ASF licenses this file to You under the Apache License, Version 2.0rem (the "License"); you may not use this file except in compliance withrem the License. You may obtain a copy of the License atremrem remrem Unless required by applicable law or agreed to in writing, softwarerem 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 andrem limitations under the License.rem ---------------------------------------------------------------------------rem Set JAVA_HOME or JRE_HOME if not already set, ensure any provided settingsrem are valid and consistent with the selected start-up options and set up therem endorsed directory.rem ---------------------------------------------------------------------------set JAVA_HOME = "D:\Program Files\Java\jdk1.7.0_71";set JRE_HOME = "D:\Program Files\Java\jre7";rem Make sure prerequisite environment variables are setrem In debug mode we need a real JDK (JAVA_HOME)if ""%1"" == ""debug"" goto needJavaHomerem Otherwise either JRE or JDK are fineif not "%JRE_HOME%" == "" goto gotJreHomeif not "%JAVA_HOME%" == "" goto gotJavaHomeecho Neither the JAVA_HOME nor the JRE_HOME environment variable is definedecho At least one of these environment variable is needed to run this programgoto exit:needJavaHomerem Check if we have a usable JDKif "%JAVA_HOME%" == "" goto noJavaHomeif not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHomeif not exist "%JAVA_HOME%\bin\javaw.exe" goto noJavaHomeif not exist "%JAVA_HOME%\bin\jdb.exe" goto noJavaHomeif not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHomeset "JRE_HOME=%JAVA_HOME%"goto okJava:noJavaHomeecho The JAVA_HOME environment variable is not defined correctly.echo It is needed to run this program in debug mode.echo NB: JAVA_HOME should point to a JDK not a JRE.goto exit:gotJavaHomerem No JRE given, use JAVA_HOME as JRE_HOMEset "JRE_HOME=%JAVA_HOME%":gotJreHomerem Check if we have a usable JREif not exist "%JRE_HOME%\bin\java.exe" goto noJreHomeif not exist "%JRE_HOME%\bin\javaw.exe" goto noJreHomegoto okJava:noJreHomerem Needed at least a JREecho The JRE_HOME environment variable is not defined correctlyecho This environment variable is needed to run this programgoto exit:okJavarem Don't override the endorsed dir if the user has set it previouslyif not "%JAVA_ENDORSED_DIRS%" == "" goto gotEndorseddirrem Set the default -Djava.endorsed.dirs argumentset "JAVA_ENDORSED_DIRS=%CATALINA_HOME%\endorsed":gotEndorseddirrem Don't override _RUNJAVA if the user has set it previouslyif not "%_RUNJAVA%" == "" goto gotRunJavarem Set standard command for invoking Java.rem Also note the quoting as JRE_HOME may contain spaces.set _RUNJAVA="%JRE_HOME%\bin\java.exe":gotRunJavarem Don't override _RUNJDB if the user has set it previouslyrem Also note the quoting as JAVA_HOME may contain spaces.if not "%_RUNJDB%" == "" goto gotRunJdbset _RUNJDB="%JAVA_HOME%\bin\jdb.exe":gotRunJdbgoto end:exitexit /b 1:endexit /b 0