解决安装tomcat时出现的问题

 更新时间:2024年02月19日 16:43:13   作者:qq_36443319  
这篇文章主要介绍了解决安装tomcat时出现的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教

在win10安装了JDK8并配置好了相关路径,在Tomcat在启动过程中出现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启动脚本:发现其调用了catalina.bat,而catalina.bat调用了setclasspath.bat

2、在setclasspath.bat的头部定义了JAVA_HOME和JRE_HOME的值,那么这里需要我们手动设置JAVA_HOME变量和JRE_HOME变量(红色代码为新添加

注意:你所设置的变量要和自己的电脑中”环境变量“里的JAVA_HOME和JRE_HOME保持一致,我的是红色的代码。

第一还是配错了路径,是应为环境变量中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 needJavaHome

rem 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”
:gotEndorseddir

rem 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"
:gotRunJava

rem 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"
:gotRunJdb

goto end

:exit
exit /b 1

:end
exit /b 0

添加变量后保存,并关闭文件,重新启动tomcat,然后在点击startup.bat,看到下面这样就说明OK了

如果是启动后再次启动出现问题,可能是你没有关闭之前启动的,造成8080端口占

有两种方案:

1.在startup.bat 同级目录中,按 shutdown.bat 关闭 (建议用此方法)

2.Tomcat服务器的配置文件,全部都在tomcat的安装目录下conf目录下:修改tomcat的端口为9090修改完server.xml文件必须重启服务器才能有效。

通过浏览器的地址栏访问测试:http://localhost:9090

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • Tomcat并发优化方法介绍

    Tomcat并发优化方法介绍

    这篇文章主要介绍了Tomcat并发优化方法介绍,小编觉得挺不错的,这里给大家分享下,供需要的朋友参考。
    2017-10-10
  • 详解windows 10中Tomcat安装和部署的教程

    详解windows 10中Tomcat安装和部署的教程

    这篇文章主要介绍了windows 10中Tomcat安装和部署教程,本文图文并茂给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-11-11
  • Java开启/关闭tomcat服务器的方法

    Java开启/关闭tomcat服务器的方法

    这篇文章主要介绍了Java开启/关闭tomcat服务器的方法,本文给大家介绍的非常详细,具有一定的参考借鉴价值 ,需要的朋友可以参考下
    2019-06-06
  • tomcat配置虚拟路径的实现步骤

    tomcat配置虚拟路径的实现步骤

    本文主要介绍了tomcat配置虚拟路径的实现步骤,主要是在localhost文件中进行配置,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-05-05
  • 简单记录Cent OS服务器配置JDK+Tomcat+MySQL

    简单记录Cent OS服务器配置JDK+Tomcat+MySQL

    这篇文章主要介绍了简单记录Cent OS服务器配置JDK+Tomcat+MySQL,需要的朋友可以参考下
    2014-12-12
  • 浅谈Tomcat如何打破双亲委托机制

    浅谈Tomcat如何打破双亲委托机制

    本文主要介绍了浅谈Tomcat如何打破双亲委托机制,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-07-07
  • 完美解决Tomcat关闭后报错问题

    完美解决Tomcat关闭后报错问题

    这篇文章主要介绍了完美解决Tomcat关闭后报错问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-06-06
  • 详述 tomcat 中的 server.xml 配置文件示例

    详述 tomcat 中的 server.xml 配置文件示例

    本文将通过实例,介绍server.xml中各个组件的配置,并详细说明 Tomcat 各个核心组件的作用以及各个组件之间的相互关系。对tomcat server.xml 配置文件相关知识感兴趣的朋友一起看看吧
    2017-08-08
  • IDEA和Tomcat服务器的整合过程

    IDEA和Tomcat服务器的整合过程

    这篇文章主要介绍了IDEA和Tomcat服务器的整合,本文分步骤通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-09-09
  • Tomcat启动springboot项目war包报错:启动子级时出错的问题

    Tomcat启动springboot项目war包报错:启动子级时出错的问题

    这篇文章主要介绍了Tomcat启动springboot项目war包报错:启动子级时出错的问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-08-08

最新评论