This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push:
new a92db2f0b4 Improve messages for invalid JRE_HOME/JAVA_HOME
a92db2f0b4 is described below
commit a92db2f0b4f98130af763e6742be4b252ccdc435
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Apr 11 10:50:04 2023 +0100
Improve messages for invalid JRE_HOME/JAVA_HOME
Align JRE_HOME/JAVA_HOME handling with setclasspath.bat
---
bin/service.bat | 49 +++++++++++++++++++++++++++++-----------------
bin/setclasspath.bat | 13 +++++++++++-
bin/setclasspath.sh | 24 ++++++++++++++++++++---
webapps/docs/changelog.xml | 6 ++++++
4 files changed, 70 insertions(+), 22 deletions(-)
diff --git a/bin/service.bat b/bin/service.bat
index a1ab56d2e2..421424470b 100755
--- a/bin/service.bat
+++ b/bin/service.bat
@@ -103,36 +103,49 @@ exit /b 1
cd "%CURRENT_DIR%"
rem Make sure prerequisite environment variables are set
-if not "%JAVA_HOME%" == "" goto gotJdkHome
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 Service will try to guess them from the registry.
-goto okJavaHome
-:gotJreHome
-if not exist "%JRE_HOME%\bin\java.exe" goto noJavaHome
-goto okJavaHome
-:gotJdkHome
-if not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHome
+goto okJava
+
+:gotJavaHome
+rem No JRE given, check if JAVA_HOME is usable as JRE_HOME
rem Java 9 has a different directory structure
if exist "%JAVA_HOME%\jre\bin\java.exe" goto preJava9Layout
-if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
-if not "%JRE_HOME%" == "" goto okJavaHome
+if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHomeAsJre
+rem Use JAVA_HOME as JRE_HOME
set "JRE_HOME=%JAVA_HOME%"
-goto okJavaHome
+goto okJava
+
:preJava9Layout
-if not "%JRE_HOME%" == "" goto okJavaHome
+rem Use JAVA_HOME\jre as JRE_HOME
set "JRE_HOME=%JAVA_HOME%\jre"
-goto okJavaHome
-:noJavaHome
-echo The JAVA_HOME environment variable is not defined correctly
+goto okJava
+
+:noJavaHomeAsJre
+echo The JAVA_HOME environment variable is not defined correctly.
+echo JAVA_HOME=%JAVA_HOME%
+echo NB: JAVA_HOME should point to a JDK not a JRE.
+exit /b 1
+
+:gotJreHome
+rem Check if we have a usable JRE
+if not exist "%JRE_HOME%\bin\java.exe" goto noJreHome
+goto okJava
+
+:noJreHome
+rem Needed at least a JRE
+echo The JRE_HOME environment variable is not defined correctly
+echo JRE_HOME=%JRE_HOME%
echo This environment variable is needed to run this program
-echo NB: JAVA_HOME should point to a JDK not a JRE
exit /b 1
-:okJavaHome
+
+:okJava
if not "%CATALINA_BASE%" == "" goto gotBase
set "CATALINA_BASE=%CATALINA_HOME%"
-:gotBase
+:gotBase
rem Java 9 no longer supports the java.endorsed.dirs
rem system property. Only try to use it if
rem JAVA_ENDORSED_DIRS was explicitly set
@@ -235,4 +248,4 @@ echo Failed installing '%SERVICE_NAME%' service
exit /b 1
:installed
echo The service '%SERVICE_NAME%' has been installed.
-exit /b 0
\ No newline at end of file
+exit /b 0
diff --git a/bin/setclasspath.bat b/bin/setclasspath.bat
index 12da138fa5..1fa46de7d0 100755
--- a/bin/setclasspath.bat
+++ b/bin/setclasspath.bat
@@ -43,13 +43,23 @@ goto okJava
:noJavaHome
echo The JAVA_HOME environment variable is not defined correctly.
+echo JAVA_HOME=%JAVA_HOME%
echo It is needed to run this program in debug mode.
echo NB: JAVA_HOME should point to a JDK not a JRE.
goto exit
:gotJavaHome
-rem No JRE given, use JAVA_HOME as JRE_HOME
+rem No JRE given, check if JAVA_HOME is usable as JRE_HOME
+if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHomeAsJre
+rem Use JAVA_HOME as JRE_HOME
set "JRE_HOME=%JAVA_HOME%"
+goto okJava
+
+:noJavaHomeAsJre
+echo The JAVA_HOME environment variable is not defined correctly.
+echo JAVA_HOME=%JAVA_HOME%
+echo NB: JAVA_HOME should point to a JDK not a JRE.
+goto exit
:gotJreHome
rem Check if we have a usable JRE
@@ -59,6 +69,7 @@ goto okJava
:noJreHome
rem Needed at least a JRE
echo The JRE_HOME environment variable is not defined correctly
+echo JRE_HOME=%JRE_HOME%
echo This environment variable is needed to run this program
goto exit
diff --git a/bin/setclasspath.sh b/bin/setclasspath.sh
index 4ae4b6a149..77f1cb2882 100755
--- a/bin/setclasspath.sh
+++ b/bin/setclasspath.sh
@@ -54,15 +54,13 @@ if [ -z "$JAVA_HOME" ] && [ "$1" = "debug" ]; then
echo "JAVA_HOME should point to a JDK in order to run in debug mode."
exit 1
fi
-if [ -z "$JRE_HOME" ]; then
- JRE_HOME="$JAVA_HOME"
-fi
# If we're running under jdb, we need a full jdk.
if [ "$1" = "debug" ] ; then
if [ "$os400" = "true" ]; then
if [ ! -x "$JAVA_HOME"/bin/java ] || [ ! -x "$JAVA_HOME"/bin/javac ]; then
echo "The JAVA_HOME environment variable is not defined correctly"
+ echo "JAVA_HOME=$JAVA_HOME"
echo "This environment variable is needed to run this program"
echo "NB: JAVA_HOME should point to a JDK not a JRE"
exit 1
@@ -70,6 +68,7 @@ if [ "$1" = "debug" ] ; then
else
if [ ! -x "$JAVA_HOME"/bin/java ] || [ ! -x "$JAVA_HOME"/bin/jdb ] || [ !
-x "$JAVA_HOME"/bin/javac ]; then
echo "The JAVA_HOME environment variable is not defined correctly"
+ echo "JAVA_HOME=$JAVA_HOME"
echo "This environment variable is needed to run this program"
echo "NB: JAVA_HOME should point to a JDK not a JRE"
exit 1
@@ -77,6 +76,25 @@ if [ "$1" = "debug" ] ; then
fi
fi
+if [ -z "$JRE_HOME" ]; then
+ # JAVA_HOME_MUST be set
+ if [ ! -x "$JAVA_HOME"/bin/java ]; then
+ echo "The JAVA_HOME environment variable is not defined correctly"
+ echo "JAVA_HOME=$JAVA_HOME"
+ echo "This environment variable is needed to run this program"
+ echo "NB: JAVA_HOME should point to a JDK not a JRE"
+ exit 1
+ fi
+ JRE_HOME="$JAVA_HOME"
+else
+ if [ ! -x "$JRE_HOME"/bin/java ]; then
+ echo "The JRE_HOME environment variable is not defined correctly"
+ echo "JRE_HOME=$JRE_HOME"
+ echo "This environment variable is needed to run this program"
+ exit 1
+ fi
+fi
+
# Don't override the endorsed dir if the user has set it previously
if [ -z "$JAVA_ENDORSED_DIRS" ]; then
# Java 9 no longer supports the java.endorsed.dirs
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 041e3d7e55..29701dd3be 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -251,6 +251,12 @@
to the jvm in <code>catalina.sh</code> when calling
<code>version</code>.
Patch suggested by Eric Hamilton. (lihan)
</fix>
+ <fix>
+ Improve the error messages if <code>JRE_HOME</code> or
+ <code>JAVA_HOME</code> are not set correctly. On windows, align the
+ handling of <code>JRE_HOME</code> and <code>JAVA_HOME</code> for the
+ start-up scripts and the service install script. (markt)
+ </fix>
</changelog>
</subsection>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]