今天在使用tomcat6.0.7時出現Tomcat啟動時一閃而過,但是jdk環境變數配置正確,並使用java或者javac命令多可以運行,但是tomcat不能運行解決辦法。
1.在命令列中直接啟動tomcat時查看錯誤資訊 如;
C:\Users\Administrator>
C:\Users\Administrator>cd D:\apache-tomcat-6.0.37\bin
C:\Users\Administrator>d:
D:\apache-tomcat-6.0.37\bin>startup.bat
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
D:\apache-tomcat-6.0.37\bin>
D:\apache-tomcat-6.0.37\bin>
2.根據以上資訊,配置java_home路徑:如java_home="D:\Program Files\java\jdk1.6.0_21\bin"
配置jre路徑: jre_home="D:\Program Files\java\jdk1.6.0_21\jre"
3.重新啟動tomcat。
4.如果以上配置完成還是不能啟動,請看下面配置. 5.由於tomcat的startup.bat啟動時,調用的是catalina.bat ,而catalina.bat調用了setclasspath.bat
在setclasspath.bat中配置的就是tomcat運行時所需的jar包及使用所需的類。
在setclasspath.bat的頭部配置JAVA_HOME和JRE_HOME的值。如下:
set JAVA_HOME=D:\Program Files\java\jdk1.6.0_21
set JRE_HOME=D:\Program Files\java\jdk1.6.0_21\jre
6.配置完成再次啟動tomcat即可。
setclasspath.bat檔案如下:
@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 ---------------------------------------------------------------------------
rem Set CLASSPATH and Java options
rem
rem $Id: setclasspath.bat 908749 2010-02-10 23:26:42Z markt $
rem ---------------------------------------------------------------------------
set JAVA_HOME=D:\Program Files\java\jdk1.6.0_21
set JRE_HOME=D:\Program Files\java\jdk1.6.0_21\jre
rem Make sure prerequisite environment variables are set
if not "%JAVA_HOME%" == "" goto gotJdkHome
if not "%JRE_HOME%" == "" goto gotJreHome
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
:gotJreHome
if not exist "%JRE_HOME%\bin\java.exe" goto noJavaHome
if not exist "%JRE_HOME%\bin\javaw.exe" goto noJavaHome
if not ""%1"" == ""debug"" goto okJavaHome
echo JAVA_HOME should point to a JDK in order to run in debug mode.
goto exit
:gotJdkHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\javaw.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\jdb.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHome
if not "%JRE_HOME%" == "" goto okJavaHome
set "JRE_HOME=%JAVA_HOME%"
goto okJavaHome
:noJavaHome
echo The JAVA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
echo NB: JAVA_HOME should point to a JDK not a JRE
goto exit
:okJavaHome
if not "%BASEDIR%" == "" goto gotBasedir
echo The BASEDIR environment variable is not defined
echo This environment variable is needed to run this program
goto exit
:gotBasedir
if exist "%BASEDIR%\bin\setclasspath.bat" goto okBasedir
echo The BASEDIR environment variable is not defined correctly
echo This environment variable is needed to run this program
goto exit
:okBasedir
rem Don't override the endorsed dir if the user has set it previously
if not "%JAVA_ENDORSED_DIRS%" == "" goto gotEndorseddir
rem Set the default -Djava.endorsed.dirs argument
set "JAVA_ENDORSED_DIRS=%BASEDIR%\endorsed"
:gotEndorseddir
rem Set standard command for invoking Java.
rem Note that NT requires a window name argument when using start.
rem Also note the quoting as JAVA_HOME may contain spaces.
set _RUNJAVA="%JRE_HOME%\bin\java"
set _RUNJDB="%JAVA_HOME%\bin\jdb"
goto end
:exit
exit /b 1
:end
exit /b 0