Tomcat安装报Neither the JAVA_HOME nor the JRE_HOME environment的错误

以下这个Tomcat的安装教程很详细

https://blog.****.net/qq_40881680/article/details/83582484#Tomcat%E4%B8%8B%E8%BD%BD%E6%95%99%E7%A8%8B

但我的问题是:(显示我没有Java的环境,可是CMD下又能搜到我的Java环境

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

Tomcat安装报Neither the JAVA_HOME nor the JRE_HOME environment的错误

可是我明明有Java的环境:

java -version 出现如下信息:

Tomcat安装报Neither the JAVA_HOME nor the JRE_HOME environment的错误

java -verbose 出现如下信息:

Tomcat安装报Neither the JAVA_HOME nor the JRE_HOME environment的错误

然而我的环境变量里找不到Java相关的环境

Tomcat安装报Neither the JAVA_HOME nor the JRE_HOME environment的错误

要么增加Java的环境变量(失败了一次),要么修改Tomcat的配置(成功)。

以下是修改Tomcat的配置的方法

Tomcat安装报Neither the JAVA_HOME nor the JRE_HOME environment的错误

编辑“startup.bat”

增加如下两行(直接定向jdk和jre文件的地址,再赋值给变量JAVA_HOME,JRE_HOME)


set JAVA_HOME=C:/Program Files/Java/jdk1.8.0_152
set JRE_HOME=C:/Program Files/Java/jre1.8.0_152

Tomcat安装报Neither the JAVA_HOME nor the JRE_HOME environment的错误

打开页面 http://localhost:8080/  成功!!

Tomcat安装报Neither the JAVA_HOME nor the JRE_HOME environment的错误

参考了:https://blog.51cto.com/7336056/1864070