解决安装tomcat时出现的问题
<div id="navCategory"><h5 class="catalogue">目录</h5><ul class="first_class_ul"><li><a href="#_label0">找出问题的原因</a></li><li><a href="#_label1">原因知道了,下面来看解决办法</a></li><li><a href="#_label2">总结</a></li></ul></div><p>在win10安装了JDK8并配置好了相关路径,在Tomcat在启动过程中出现startup.bat时闪退。</p><p class="maodian"><a name="_label0"></a></p><h2>找出问题的原因</h2>
<p>右键编辑打开“startup.bat"文件,然后找文件的最后一行代码是:end 在:end的后面输入pause</p>
<p>如下图所示:</p>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202402/2024021911481716.png" /></p>
<p>接下来在DOS命令窗口运行startup.bat</p>
<p>此时提示报错信息如下:</p>
<blockquote><p>the JRE_HOME environment variable is not defined correctly This environment variabl</p></blockquote>
<p class="maodian"><a name="_label1"></a></p><h2>原因知道了,下面来看解决办法</h2>
<p>1、分析startup.bat启动脚本:发现其调用了catalina.bat,而catalina.bat调用了setclasspath.bat</p>
<p>2、在setclasspath.bat的头部定义了JAVA_HOME和JRE_HOME的值,那么这里需要我们手动设置JAVA_HOME变量和JRE_HOME变量(红色代码为新添加</p>
<p>注意:你所设置的变量要和自己的电脑中”环境变量“里的JAVA_HOME和JRE_HOME保持一致,我的是红色的代码。</p>
<p>第一还是配错了路径,是应为环境变量中JRE_HOME的问题。</p>
<p>错把jre的绝对路径放在JAVA_HOME中了。</p>
<p>把JAVA_HOME中的jre的绝对路径删除掉。</p>
<p>重新建一个JRE_HOME,并且加入jre的绝对路径。</p>
<p><strong>改完后就如下:</strong></p>
<blockquote><p>@echo off<br />rem Licensed to the Apache Software Foundation (ASF) under one or more<br />rem contributor license agreements. See the NOTICE file distributed with<br />rem this work for additional information regarding copyright ownership.<br />rem The ASF licenses this file to You under the Apache License, Version 2.0<br />rem (the “License”); you may not use this file except in compliance with<br />rem the License. You may obtain a copy of the License at<br />rem<br />rem http://www.apache.org/licenses/LICENSE-2.0<br />rem<br />rem Unless required by applicable law or agreed to in writing, software<br />rem distributed under the License is distributed on an “AS IS” BASIS,<br />rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br />rem See the License for the specific language governing permissions and<br />rem limitations under the License.</p>
<p>rem ---------------------------------------------------------------------------<br />rem Set JAVA_HOME or JRE_HOME if not already set, ensure any provided settings<br />rem are valid and consistent with the selected start-up options and set up the<br />rem endorsed directory.<br />rem ---------------------------------------------------------------------------</p></blockquote>
<p><strong>set JAVA_HOME=D:\D:\tomcat\apache-tomcat-8.5.43</strong></p>
<p><strong>set JRE_HOME= C:\Program Files\Java\jre-9.0.4 </strong></p>
<blockquote><p>rem Make sure prerequisite environment variables are set</p>
<p>rem In debug mode we need a real JDK (JAVA_HOME)<br />if “”%1"" == ““debug”” goto needJavaHome</p>
<p>rem Otherwise either JRE or JDK are fine<br />if not “%JRE_HOME%” == “” goto gotJreHome<br />if not “%JAVA_HOME%” == “” goto gotJavaHome<br />echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined<br />echo At least one of these environment variable is needed to run this program<br />goto exit</p>
<p>:needJavaHome<br />rem Check if we have a usable JDK<br />if “%JAVA_HOME%” == “” goto noJavaHome<br />if not exist “%JAVA_HOME%\bin\java.exe” goto noJavaHome<br />if not exist “%JAVA_HOME%\bin\javaw.exe” goto noJavaHome<br />if not exist “%JAVA_HOME%\bin\jdb.exe” goto noJavaHome<br />if not exist “%JAVA_HOME%\bin\javac.exe” goto noJavaHome<br />set “JRE_HOME=%JAVA_HOME%”<br />goto okJava</p>
<p>:noJavaHome<br />echo The JAVA_HOME environment variable is not defined correctly.<br />echo It is needed to run this program in debug mode.<br />echo NB: JAVA_HOME should point to a JDK not a JRE.<br />goto exit</p>
<p>:gotJavaHome<br />rem No JRE given, use JAVA_HOME as JRE_HOME<br />set “JRE_HOME=%JAVA_HOME%”</p>
<p>:gotJreHome<br />rem Check if we have a usable JRE<br />if not exist “%JRE_HOME%\bin\java.exe” goto noJreHome<br />if not exist “%JRE_HOME%\bin\javaw.exe” goto noJreHome<br />goto okJava</p>
<p>:noJreHome<br />rem Needed at least a JRE<br />echo The JRE_HOME environment variable is not defined correctly<br />echo This environment variable is needed to run this program<br />goto exit</p>
<p>:okJava<br />rem Don’t override the endorsed dir if the user has set it previously<br />if not “%JAVA_ENDORSED_DIRS%” == “” goto gotEndorseddir<br />rem Set the default -Djava.endorsed.dirs argument<br />set “JAVA_ENDORSED_DIRS=%CATALINA_HOME%\endorsed”<br />:gotEndorseddir</p>
<p>rem Don’t override _RUNJAVA if the user has set it previously<br />if not “%_RUNJAVA%” == “” goto gotRunJava<br />rem Set standard command for invoking Java.<br />rem Also note the quoting as JRE_HOME may contain spaces.<br />set _RUNJAVA="%JRE_HOME%\bin\java.exe"<br />:gotRunJava</p>
<p>rem Don’t override _RUNJDB if the user has set it previously<br />rem Also note the quoting as JAVA_HOME may contain spaces.<br />if not “%_RUNJDB%” == “” goto gotRunJdb<br />set _RUNJDB="%JAVA_HOME%\bin\jdb.exe"<br />:gotRunJdb</p>
<p>goto end</p>
<p>:exit<br />exit /b 1</p>
<p>:end<br />exit /b 0</p></blockquote>
<p>添加变量后保存,并关闭文件,重新启动tomcat,然后在点击startup.bat,看到下面这样就说明OK了</p>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202402/2024021911481717.jpg" /></p>
<p>如果是启动后再次启动出现问题,可能是你没有关闭之前启动的,造成8080端口占</p>
<p><strong>有两种方案:</strong></p>
<p>1.在startup.bat 同级目录中,按 shutdown.bat 关闭 (建议用此方法)</p>
<p>2.Tomcat服务器的配置文件,全部都在tomcat的安装目录下conf目录下:修改tomcat的端口为9090修改完server.xml文件必须重启服务器才能有效。</p>
<p>通过浏览器的地址栏访问测试:http://localhost:9090</p>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202402/2024021911481718.png" /></p>
<p class="maodian"><a name="_label2"></a></p><h2>总结</h2>
<p>以上为个人经验,希望能给大家一个参考,也希望大家多多支持琼殿技术社区。</p>
頁:
[1]