在winserver上明明已經安裝了JDK1.6并設定好了JAVA_HOME,可偏偏Tomcat在啟動過程中找不到。
報錯資訊如下: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 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 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 ---------------------------------------------------------------------------
rem Set JAVA_HOME or JRE_HOME if not already set, ensure any provided settings
rem are valid and consistent with the selected start-up options and set up the
rem endorsed directory.
rem $Id: setclasspath.bat 1202062 2011-11-15 06:50:02Z mturk $
##注意這裡添加的路徑要使用自己安裝的java路徑
set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_10
set JRE_HOME=C:\Program Files (x86)\Java\jdk1.6.0_10
rem Make sure prerequisite environment variables are set
rem In debug mode we need a real JDK (JAVA_HOME)
if ""%1"" == ""debug"" goto needJavaHome
rem Otherwise either JRE or JDK are fine
if not "%JRE_HOME%" == "" goto gotJreHome
if not "%JAVA_HOME%" == "" goto gotJavaHome
echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
echo At least one of these environment variable is needed to run this program
goto exit
............ 中間省略
goto end
:exit
exit /b 1
:end
exit /b 0
3、重新開機tomcat,敲入
http://localhost:8080驗證,問題解決。