解決安裝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)其調用了catalina.bat,而catalina.bat調用了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
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
簡單記錄Cent OS服務器配置JDK+Tomcat+MySQL
這篇文章主要介紹了簡單記錄Cent OS服務器配置JDK+Tomcat+MySQL,需要的朋友可以參考下2014-12-12詳述 tomcat 中的 server.xml 配置文件示例
本文將通過實例,介紹server.xml中各個組件的配置,并詳細說明 Tomcat 各個核心組件的作用以及各個組件之間的相互關系。對tomcat server.xml 配置文件相關知識感興趣的朋友一起看看吧2017-08-08Tomcat啟動springboot項目war包報錯:啟動子級時出錯的問題
這篇文章主要介紹了Tomcat啟動springboot項目war包報錯:啟動子級時出錯的問題,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-08-08