JDK环境变量安装正确还报错的情况解决方案

环境变量 JAVA_HOME , PATH 都已配置完毕,并且 java -version也显示正确如下

E:\apache-tomcat-8.0.30-windows-x64\apache-tomcat-8.0.30\bin>java -version
java version "1.8.0_71"
Java(TM) SE Runtime Environment (build 1.8.0_71-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.71-b15, mixed mode)

 

运行tomcat还出现以下报错提示:

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的startup.bat,它调用了catalina.bat,而catalina.bat则调用了setclasspath.bat。只要在setclasspath.bat的开头声明环境变量,如我的就是: 用记事本打开setclasspath.bat

 

rem ---------------------------------------------------------------------------
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 ---------------------------------------------------------------------------
set JAVA_HOME=E:/Java/jdk1.8.0_71

rem Make sure prerequisite environment variables are set

rem In debug mode we need a real JDK (JAVA_HOME)
if ""%1"" == ""debug"" goto needJavaHome

......

 

/**增加了 红色的代码****/

这样在每次运行startup.bat时就注册了JAVA_HOME,JRE_HOME。控制台窗口关闭后,这两个变量也将消失,不会再占用内存。运行一下,最终提示“信息:Server startup in xxxxx ms”就大功告成了。

posted @ 2016-01-29 11:37  龙鸿轩  阅读(936)  评论(0编辑  收藏  举报