解決安裝tomcat時(shí)出現(xiàn)的問(wèn)題
在win10安裝了JDK8并配置好了相關(guān)路徑,在Tomcat在啟動(dòng)過(guò)程中出現(xiàn)startup.bat時(shí)閃退。
找出問(wèn)題的原因
右鍵編輯打開(kāi)“startup.bat"文件,然后找文件的最后一行代碼是:end 在:end的后面輸入pause
如下圖所示:
接下來(lái)在DOS命令窗口運(yùn)行startup.bat
此時(shí)提示報(bào)錯(cuò)信息如下:
the JRE_HOME environment variable is not defined correctly This environment variabl
原因知道了,下面來(lái)看解決辦法
1、分析startup.bat啟動(dòng)腳本:發(fā)現(xiàn)其調(diào)用了catalina.bat,而catalina.bat調(diào)用了setclasspath.bat
2、在setclasspath.bat的頭部定義了JAVA_HOME和JRE_HOME的值,那么這里需要我們手動(dòng)設(shè)置JAVA_HOME變量和JRE_HOME變量(紅色代碼為新添加
注意:你所設(shè)置的變量要和自己的電腦中”環(huán)境變量“里的JAVA_HOME和JRE_HOME保持一致,我的是紅色的代碼。
第一還是配錯(cuò)了路徑,是應(yīng)為環(huán)境變量中JRE_HOME的問(wèn)題。
錯(cuò)把jre的絕對(duì)路徑放在JAVA_HOME中了。
把JAVA_HOME中的jre的絕對(duì)路徑刪除掉。
重新建一個(gè)JRE_HOME,并且加入jre的絕對(duì)路徑。
改完后就如下:
@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
添加變量后保存,并關(guān)閉文件,重新啟動(dòng)tomcat,然后在點(diǎn)擊startup.bat,看到下面這樣就說(shuō)明OK了
如果是啟動(dòng)后再次啟動(dòng)出現(xiàn)問(wèn)題,可能是你沒(méi)有關(guān)閉之前啟動(dòng)的,造成8080端口占
有兩種方案:
1.在startup.bat 同級(jí)目錄中,按 shutdown.bat 關(guān)閉 (建議用此方法)
2.Tomcat服務(wù)器的配置文件,全部都在tomcat的安裝目錄下conf目錄下:修改tomcat的端口為9090修改完server.xml文件必須重啟服務(wù)器才能有效。
通過(guò)瀏覽器的地址欄訪問(wèn)測(cè)試:http://localhost:9090
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java開(kāi)啟/關(guān)閉tomcat服務(wù)器的方法
這篇文章主要介紹了Java開(kāi)啟/關(guān)閉tomcat服務(wù)器的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2019-06-06簡(jiǎn)單記錄Cent OS服務(wù)器配置JDK+Tomcat+MySQL
這篇文章主要介紹了簡(jiǎn)單記錄Cent OS服務(wù)器配置JDK+Tomcat+MySQL,需要的朋友可以參考下2014-12-12完美解決Tomcat關(guān)閉后報(bào)錯(cuò)問(wèn)題
這篇文章主要介紹了完美解決Tomcat關(guān)閉后報(bào)錯(cuò)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06詳述 tomcat 中的 server.xml 配置文件示例
本文將通過(guò)實(shí)例,介紹server.xml中各個(gè)組件的配置,并詳細(xì)說(shuō)明 Tomcat 各個(gè)核心組件的作用以及各個(gè)組件之間的相互關(guān)系。對(duì)tomcat server.xml 配置文件相關(guān)知識(shí)感興趣的朋友一起看看吧2017-08-08Tomcat啟動(dòng)springboot項(xiàng)目war包報(bào)錯(cuò):?jiǎn)?dòng)子級(jí)時(shí)出錯(cuò)的問(wèn)題
這篇文章主要介紹了Tomcat啟動(dòng)springboot項(xiàng)目war包報(bào)錯(cuò):?jiǎn)?dòng)子級(jí)時(shí)出錯(cuò)的問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-08-08