tomcat启动时错误Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of th

安装好tomcat之后,发现除了使用sudo命令之外,执行命令   ./startup.sh

就会出现以下错误:

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

原来是我使用的jdk不是通过yum安装的,是我从官网直接下载的,虽然我修改了java_home,但不太智能的tomcat仍然没有自动识别出java_home路径。

原因:

因为启动tomcat会调用tomcat安装文件中的startup.bat,而它调用了catalina.bat则调用了setclasspath.bat。因此需要在setclasspath.bat的开头手动声明环境变量。


解决:

用vim打开tomcat的bin目录下的setclasspath.sh添加JAVA_HOME和JRE_HOME两个环境变量(下图红色方框内),两个环境变量路径为您安装的java JDK的路径。

windows下将export改为set即可。

tomcat启动时错误Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of th

保存并且退出即可。