错误描述
通过tomcat/bin/startup.bat启动tomcat时遇到报错
the jre_home environment variable is not defined correctly this environment variable is needed to run this program
终端界面一闪而过,发现启动失败,这是由于tomcat在环境变量中检索java环境是出现错误
追根溯源
打开bat文件查看,其中没有关于jre_home的报错信息,发现又运行了catalina.bat
set "executable=%catalina_home%\bin\catalina.bat"
既没有关于catalina环境配置的报错,又执行了catalina.bat,那么我们就查看一下是不是在catalina.bat中抛出的jre环境变量报错
阅读bat代码,发现第一个有关java环境的代码块
rem get standard java environment variables if exist "%catalina_home%\bin\setclasspath.bat" goto oksetclasspath echo cannot find "%catalina_home%\bin\setclasspath.bat" echo this file is needed to run this program goto end :oksetclasspath call "%catalina_home%\bin\setclasspath.bat" %1 if errorlevel 1 goto end
这里尝试从setclasspath.bat中获取java environment,正符合我们的猜想,继续查看setclasspath.bat
阅读bat,发现我们触发的报错代码
: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
回溯调用源
: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
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
通过代码我们知道,如果我们不在"debug"模式下,就会继续检索jre或jdk任意一个来支持我们在非调试模式下的运行,很明显,我们在查找jre_home时就出现了问题,从而引发报错,接下来尝试解决这个问题
问题解决
1.添加jre_home环境变量
- win+r 输入sysdm.cpl打开系统属性->高级->环境变量
- 在系统变量中新建jre_home 值为jre路径
到这里,如果问题解决了,恭喜你,但是很多人和我一样配置完毕后运行还是报错,请参考方法2
2.直接在脚本中增加静态变量
既然最终会在setclasspath.bat中查找环境变量,那么我们就直接在这里指明环境变量位置,而不必让其从系统配置中逐步检索了
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 --------------------------------------------------------------------------- rem make sure prerequisite environment variables are set set java_home=d:\java_8 set jre_home=d:\java_8\jre
直接在脚本开头写好home参数,注意将路径改为自己的
再次运行,成功
成功检索到jre
到此这篇关于tomcat 启动找不到配置的环境变量解决的文章就介绍到这了,更多相关tomcat 启动找不到配置内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论