119人参与 • 2024-12-04 • 缓存
通过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时就出现了问题,从而引发报错,接下来尝试解决这个问题
到这里,如果问题解决了,恭喜你,但是很多人和我一样配置完毕后运行还是报错,请参考方法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 启动找不到配置内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论