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


linux下,關閉和重啟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以前是正常的,突然重啟下tomcat時報了這個錯,錯誤大致是環境變量不可用造成的,

在網上找了很久都是說要修改setclasspath.bat(該文件路徑在tomcat的bin目錄下)文件;在文件中加入JAVA_HOME和JRE_HOME的環境變量,

我也在該文件中加了如下:

rem Make sure prerequisite environment variables are set

rem In debug mode we need a real JDK (JAVA_HOME)

export JAVA_HOME=/usr/local/jdk1.7.0_79
export JRE_HOME=${JAVA_HOME}/jre

if ""%1"" == ""debug"" goto needJavaHome

rem Otherwise either JRE or JDK are fine
if not "%JRE_HOME%" == "" goto gotJreHome
if not "%JAVA_HOME%" == "" goto gotJavaHome
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

:needJavaHome
rem Check if we have a usable JDK
if "%JAVA_HOME%" == "" goto noJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\javaw.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\jdb.exe" goto noJavaHome
"setclasspath.bat" [dos] 97L, 3509C

保存好文件,再次運行./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

崩潰了,網上就這么一種解決問題的方法;

突然我意識上閃出一個念頭,前面使用tomcat也是正常的,會不會在linux在運行的內存里面丟失了JAVA_HOME和JRE_HOME

的環境變量參數,如果是那樣,就重新寫入/etc/profile環境變量就ok了。

接着我運行了#source /etc/profile

重新寫入profile配置文件

運行#java -version 

奇跡出現了

java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

切換到tomcat的bin目錄下

運行#./startup.sh

tomcat運行成功!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM