双击startup.bat后出现Neither the JAVA_HOME or the JRE_HOME environmental variable is defined

tomcat 一闪而过,Neither the JAVA_HOME or the JRE_HOME environmental variable is defined.

当你下载一个压缩包解压后,到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。好,再去下载个最新版本的JDK,Install完成之后却还是提示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(例如我使用的JDK1.7)安装后不会自动创建环境变量JAVA_HOME,JRE_HOME。

方法一:

先看Tomcat的startup.bat,它调用了catalina.bat(CATALINA是Servlet的容器),而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=C:\jdk6.0
set JRE_HOME=C:\jre1.6.0

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。控制台窗口关闭后,这两个变量也将消失,不会再占用内存。运行一下,最终提示“信息:Server startup in xxxxx ms”就大功告成了。

方法二:

右击我的电脑|属性|高级|环境变量|在系统变量下新建一个JAVA_HOME=path/java/jdk;再新建一个JRE_HOME=path/java/jre;

像我的是:JAVA_HOME=D:\Program Files\Java\jdk1.7.0_03;JRE_HOME=D:\Program Files\Java\jre7;

现在去开启startup.bat应该没问题了。

原文地址:https://www.cnblogs.com/JavaTechLover/p/2560490.html