Issue
I have installed Java 11 and set up system variables as:
JAVA_HOME
C:\Program Files\AdoptOpenJDK\jdk-11.0.5.10-hotspot
and Path to
C:\Program Files\AdoptOpenJDK\jdk-11.0.5.10-hotspot\bin
When I try to install tomcat as service using service.bat, I got the below error:
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
I did research online. My paths is set up correctly. Some solution said to install java in the directory without spaces, but I am getting same error.
The echo java command is giving me the right output
echo %JAVA_HOME%
C:\Program Files\AdoptOpenJDK\jdk-11.0.5.10-hotspot
Any help is appreciated. Thanks
Edit1: To Andres answer, below is my line 57 -69
rem Make sure prerequisite environment variables are set
if not "%JAVA_HOME%" == "" goto gotJdkHome
if not "%JRE_HOME%" == "" goto gotJreHome
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
if not exist "%JRE_HOME%\bin\javaw.exe" goto noJavaHome
goto okJavaHome
:gotJdkHome
if not exist "%JAVA_HOME%\jre\bin\java.exe" goto noJavaHome
if not exist "%JAVA_HOME%\jre\bin\javaw.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHome
if not "%JRE_HOME%" == "" goto okJavaHome
set "JRE_HOME=%JAVA_HOME%\jre"
goto okJavaHome
:noJavaHome
echo The JAVA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
echo NB: JAVA_HOME should point to a JDK not a JRE
goto end
:okJavaHome
Solution
I had to install JRE 11 on my laptop and paste it inside the JDK folder. And then I was able to install tomcat as a service with the same path and JAVA_HOME as mentioned in my question.
Answered By - Rose
Answer Checked By - Marilyn (JavaFixing Volunteer)