解決安裝tomcat時出現(xiàn)的問題
在win10安裝了JDK8并配置好了相關路徑,在Tomcat在啟動過程中出現(xiàn)startup.bat時閃退。
找出問題的原因
右鍵編輯打開“startup.bat"文件,然后找文件的最后一行代碼是:end 在:end的后面輸入pause
如下圖所示:

接下來在DOS命令窗口運行startup.bat
此時提示報錯信息如下:
the JRE_HOME environment variable is not defined correctly This environment variabl
原因知道了,下面來看解決辦法
1、分析startup.bat啟動腳本:發(fā)現(xiàn)其調(diào)用了catalina.bat,而catalina.bat調(diào)用了setclasspath.bat
2、在setclasspath.bat的頭部定義了JAVA_HOME和JRE_HOME的值,那么這里需要我們手動設置JAVA_HOME變量和JRE_HOME變量(紅色代碼為新添加
注意:你所設置的變量要和自己的電腦中”環(huán)境變量“里的JAVA_HOME和JRE_HOME保持一致,我的是紅色的代碼。
第一還是配錯了路徑,是應為環(huán)境變量中JRE_HOME的問題。
錯把jre的絕對路徑放在JAVA_HOME中了。
把JAVA_HOME中的jre的絕對路徑刪除掉。
重新建一個JRE_HOME,并且加入jre的絕對路徑。
改完后就如下:
@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 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 ---------------------------------------------------------------------------
set JAVA_HOME=D:\D:\tomcat\apache-tomcat-8.5.43
set JRE_HOME= C:\Program Files\Java\jre-9.0.4
rem Make sure prerequisite environment variables are set
rem In debug mode we need a real JDK (JAVA_HOME)
if “”%1"" == ““debug”” goto needJavaHomerem 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:needJavaHome
rem Check if we have a usable JDK
if “%JAVA_HOME%” == “” goto noJavaHome
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
set “JRE_HOME=%JAVA_HOME%”
goto okJava:noJavaHome
echo 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:gotJavaHome
rem No JRE given, use JAVA_HOME as JRE_HOME
set “JRE_HOME=%JAVA_HOME%”:gotJreHome
rem Check if we have a usable JRE
if not exist “%JRE_HOME%\bin\java.exe” goto noJreHome
if not exist “%JRE_HOME%\bin\javaw.exe” goto noJreHome
goto okJava:noJreHome
rem Needed at least a JRE
echo The JRE_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto exit:okJava
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=%CATALINA_HOME%\endorsed”
:gotEndorseddirrem Don’t override _RUNJAVA if the user has set it previously
if not “%_RUNJAVA%” == “” goto gotRunJava
rem 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 previously
rem Also note the quoting as JAVA_HOME may contain spaces.
if not “%_RUNJDB%” == “” goto gotRunJdb
set _RUNJDB="%JAVA_HOME%\bin\jdb.exe"
:gotRunJdbgoto end
:exit
exit /b 1:end
exit /b 0
添加變量后保存,并關閉文件,重新啟動tomcat,然后在點擊startup.bat,看到下面這樣就說明OK了

如果是啟動后再次啟動出現(xiàn)問題,可能是你沒有關閉之前啟動的,造成8080端口占
有兩種方案:
1.在startup.bat 同級目錄中,按 shutdown.bat 關閉 (建議用此方法)
2.Tomcat服務器的配置文件,全部都在tomcat的安裝目錄下conf目錄下:修改tomcat的端口為9090修改完server.xml文件必須重啟服務器才能有效。
通過瀏覽器的地址欄訪問測試:http://localhost:9090

總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
tomcat啟動報錯:java.util.zip.ZipException的解決方法
這篇文章主要給大家介紹了關于tomcat啟動報:java.util.zip.ZipException錯誤的解決方法,文中通過示例代碼介紹的非常詳細,同樣遇到這個問題的朋友可以參考借鑒,下面隨著小編來一起學習學習吧2018-08-08
Eclipse部署Tomcat實現(xiàn)JSP運行的超詳細教程
這篇文章主要介紹了Eclipse部署Tomcat實現(xiàn)JSP運行,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-08-08
Eclipse/tomcat 如何實現(xiàn)熱部署和熱啟動
這篇文章主要介紹了Eclipse/ tomcat 如何實現(xiàn)熱部署和熱啟動,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09
Tomcat 7-dbcp配置數(shù)據(jù)庫連接池詳解
這篇文章主要介紹了Tomcat 7-dbcp配置數(shù)據(jù)庫連接池詳解的相關資料,需要的朋友可以參考下2017-04-04
如何在IntelliJ IDEA 2018上配置Tomcat并運行第一個JavaWeb項目
這篇文章主要介紹了在IntelliJ IDEA 2018上配置Tomcat并運行第一個JavaWeb項目,需要的朋友可以參考下2020-09-09

