This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.1.x by this push:
     new b1709064e3 Improve messages for invalid JRE_HOME/JAVA_HOME
b1709064e3 is described below

commit b1709064e39dc78e104731d5860ebc75a5824fb7
Author: Mark Thomas <ma...@apache.org>
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            | 43 +++++++++++++++++++++++++++----------------
 bin/setclasspath.bat       | 13 ++++++++++++-
 bin/setclasspath.sh        | 24 +++++++++++++++++++++---
 webapps/docs/changelog.xml |  6 ++++++
 4 files changed, 66 insertions(+), 20 deletions(-)

diff --git a/bin/service.bat b/bin/service.bat
index fae79207b2..be6eca7e03 100755
--- a/bin/service.bat
+++ b/bin/service.bat
@@ -103,30 +103,42 @@ 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
-if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
-if not "%JRE_HOME%" == "" goto okJavaHome
+goto okJava
+
+:gotJavaHome
+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 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 Process the requested command
 if /i %SERVICE_CMD% == install goto doInstall
 if /i %SERVICE_CMD% == remove goto doRemove
@@ -160,7 +172,6 @@ rem Install the service
 echo Installing the service '%SERVICE_NAME%' ...
 echo Using CATALINA_HOME:    "%CATALINA_HOME%"
 echo Using CATALINA_BASE:    "%CATALINA_BASE%"
-echo Using JAVA_HOME:        "%JAVA_HOME%"
 echo Using JRE_HOME:         "%JRE_HOME%"
 
 rem Try to use the server jvm
diff --git a/bin/setclasspath.bat b/bin/setclasspath.bat
index 41548ef726..62e5d70cb3 100755
--- a/bin/setclasspath.bat
+++ b/bin/setclasspath.bat
@@ -42,13 +42,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
@@ -58,6 +68,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 b81bc197d1..f56b2aa473 100755
--- a/bin/setclasspath.sh
+++ b/bin/setclasspath.sh
@@ -53,15 +53,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
@@ -69,6 +67,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
@@ -76,6 +75,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
+
 # Set standard commands for invoking Java, if not already set.
 if [ -z "$_RUNJAVA" ]; then
   _RUNJAVA="$JRE_HOME"/bin/java
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index b5792a67e3..2f51ecdf73 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -281,6 +281,12 @@
         2.10.0-SNAPSHOT). This corrects a regression introduced in 10.1.5.
         (markt)
       </update>
+      <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: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to