欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

tomcat启动报错:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined

程序员文章站 2022-10-27 15:43:01
windows系统: 部署了一个Tomcat8.5.15,bin目录下startup.bat执行,结果提示Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these envi ......

windows系统:

部署了一个tomcat8.5.15,bin目录下startup.bat执行,结果提示neither the java_home nor the jre_home environment variable is defined at least one of these environment variable is needed to run this program。

解决方式:

在setclasspath.bat的开头声明环境变量。如图所示:

先看tomcat的startup.bat,它调用了catalina.bat,而catalina.bat则调用了setclasspath.bat。只要在setclasspath.bat的开头声明环境变量,如我的就是:

rem ---------------------------------------------------------------------------
rem set classpath and java options
rem
rem $id: setclasspath.bat 505241 2007-02-09 10:22:58z jfclere $
rem ---------------------------------------------------------------------------

set java_home=e:\java\jdk1.8.0_151
set jre_home=e:\java\jre8

rem make sure prerequisite environment variables are set
if not "%java_home%" == "" goto gotjdkhome
if not "%jre_home%" == "" goto gotjrehome
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
......

这样在每次运行startup.bat时就注册了java_home,jre_home。控制台窗口关闭后,这两个变量也将消失,不会再占用内存


linux系统:

在tomcat的bin目录下,编辑catalina.sh文件,加入

export java_home=/usr/local/java/jdk1.8.0_151

export jre_home=/usr/local/java/jdk1.8.0_151/jre

这两行,重新启动就正常!