Neither the JAVA_HOME nor the JRE_HOME environment variable is defined


很多人下载Tomcat后跑到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.8)安装完不会自动登记环境变量JAVA_HOME,JRE_HOME。下面说个不用配置环境变量的方法:


先看Tomcat的startup.bat,它调用了catalina.bat,而catalina.bat则调用了setclasspath.bat。只要在setclasspath.bat的开头声明环境变量,找到bin目录下的setclasspath.bat添加下面两行,记得改为你的Tomcat安装路径

@echo off

rem Licensed to the Apache Software Foundation (ASF) under one or more

rem contributor license agreements.  See the NOTICE file distributed with

rem this work for additional information regarding copyright ownership.

rem The ASF licenses this file to You under the Apache License, Version 2.0

rem (the "License"); you may not use this file except in compliance with

rem the License.  You may obtain a copy of the License at

rem

rem     http://www.apache.org/licenses/LICENSE-2.0

rem

rem Unless required by applicable law or agreed to in writing, software

rem distributed under the License is distributed on an "AS IS" BASIS,

rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

rem See the License for the specific language governing permissions and

rem limitations under the License.


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=D:\Program Files (x86)\Java\jdk1.8.0_60

set JRE_HOME=D:\Program Files (x86)\Java\jdk1.8.0_60\jre


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”就大功告成了。

你可能感兴趣的:(tomcat,环境变量)