[Tomcat] Service was not installed

Problems with the Windows version of XAMPP, questions, comments, and anything related.

[Tomcat] Service was not installed

Postby overdrive » 29. March 2024 23:01

Version xampp: 8.2.12
OS: Windows 11
Java: JDK 17

From the Xampp control panel (admin mode) you cannot install the Tomcat service.

I have gone to the tomcat folder within the xampp installation path, and the files tomcat_service_install.bat and tomcat_service_uninstall.bat were not running correctly.

I had fixed Tomcat batch files:

tomcat_service_install.bat

Code: Select all
@echo off

if "%OS%" == "Windows_NT" goto WinNT

:Win9X
echo Don't be stupid! Win9x don't know Services
goto exit

:WinNT

echo [XAMPP]: Searching JDK HOME with reg query ...
set KeyName=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK

reg query "%KeyName%" /s
if %ERRORLEVEL% == 1 (
  echo . [XAMPP]: Cannot find current JDK installation!
  echo . [XAMPP]: Cannot set JAVA_HOME. Aborting ...
  goto :END
)

set "CURRENT_DIR=%cd%"
set "CATALINA_HOME=%CURRENT_DIR%"

set Cmd=reg query "%KeyName%" /s
for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JAVA_HOME=%%j

echo.
echo [XAMPP]: Seems fine!
echo [XAMPP]: Using %JAVA_HOME%
echo.

set JRE_HOME=%JAVA_HOME%

echo [XAMPP]: Using JAVA_HOME=%JAVA_HOME%
echo [XAMPP]: Using CATALINA_HOME=%CATALINA_HOME%
echo [XAMPP]: Using JRE_HOME=%JRE_HOME%

echo Installing Tomcat as an Service

cd "%CURRENT_DIR%\bin"

call service.bat install Tomcat8.exe

cd "%CURRENT_DIR%"

goto exit

:END

:exit


tomcat_service_uninstall.bat

Code: Select all
@echo off

if "%OS%" == "Windows_NT" goto WinNT

:Win9X
echo Don't be stupid! Win9x don't know Services
goto exit

:WinNT

echo [XAMPP]: Searching JDK HOME with reg query ...
set KeyName=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK

reg query "%KeyName%" /s
if %ERRORLEVEL% == 1 (
  echo . [XAMPP]: Cannot find current JDK installation!
  echo . [XAMPP]: Cannot set JAVA_HOME. Aborting ...
  goto :END
)

set "CURRENT_DIR=%cd%"
set "CATALINA_HOME=%CURRENT_DIR%"

set Cmd=reg query "%KeyName%" /s
for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JAVA_HOME=%%j

echo.
echo [XAMPP]: Seems fine!
echo [XAMPP]: Using %JAVA_HOME%
echo.
 
set JRE_HOME=%JAVA_HOME%

echo [XAMPP]: Using JAVA_HOME=%JAVA_HOME%
echo [XAMPP]: Using CATALINA_HOME=%CATALINA_HOME%
echo [XAMPP]: Using JRE_HOME=%JRE_HOME%

echo Try to stop Tomcat7 service
net stop Tomcat7
echo Uninstall Tomcat as an Service

cd "%CURRENT_DIR%\bin"

echo In original file triggers Tomcat7
call service.bat remove Tomcat8.exe

cd "%CURRENT_DIR%"

goto exit

:END

:exit


Although running these files the service is created, the action of activating the service from the xampp control panel is broken.

Image
Image
overdrive
 
Posts: 4
Joined: 29. March 2024 16:47
XAMPP version: 8.2.12
Operating System: Windows 11

Re: [Tomcat] Service was not installed

Postby overdrive » 31. March 2024 23:44

Fixed the action of activating the service from the xampp control panel is broken.

Services.bat from ...\xampp\tomcat\bin
Code: Select all
@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 NT Service Install/Uninstall script
rem
rem Usage: service.bat install/remove [service_name [--rename]] [--user username]
rem
rem Options
rem install                 Install the service using default settings.
rem remove                  Remove the service from the system.
rem
rem service_name (optional) The name to use for the service. If not specified,
rem                         Tomcat8 is used as the service name.
rem
rem --rename     (optional) Rename tomcat8.exe and tomcat8w.exe to match
rem                         the non-default service name.
rem
rem username     (optional) The name of the OS user to use to install/remove
rem                         the service (not the name of the OS user the
rem                         service will run as). If not specified, the current
rem                         user is used.
rem ---------------------------------------------------------------------------

setlocal

set "SELF=%~dp0%service.bat"

set DEFAULT_SERVICE_NAME=Tomcat8
set SERVICE_NAME=%DEFAULT_SERVICE_NAME%

set "CURRENT_DIR=%cd%"

rem Parse the arguments
if "x%1x" == "xx" goto displayUsage
set SERVICE_CMD=%1
shift
if "x%1x" == "xx" goto checkEnv
:checkUser
if "x%1x" == "x/userx" goto runAsUser
if "x%1x" == "x--userx" goto runAsUser
set SERVICE_NAME=%1
shift
if "x%1x" == "xx" goto checkEnv
if "x%1x" == "x--renamex" (
    set RENAME=%1
    shift
)
if "x%1x" == "xx" goto checkEnv
goto checkUser
:runAsUser
shift
if "x%1x" == "xx" goto displayUsage
set SERVICE_USER=%1
shift
runas /env /savecred /user:%SERVICE_USER% "%COMSPEC% /K \"%SELF%\" %SERVICE_CMD% %SERVICE_NAME%"
exit /b 0

rem Check the environment
:checkEnv

rem Guess CATALINA_HOME if not defined
if not "%CATALINA_HOME%" == "" goto gotHome
set "CATALINA_HOME=%cd%"
if exist "%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe" goto gotHome
if exist "%CATALINA_HOME%\bin\%SERVICE_NAME%.exe" goto gotHome
rem CD to the upper dir
cd ..
set "CATALINA_HOME=%cd%"
:gotHome
if exist "%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe" (
    set "EXECUTABLE=%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe"
    goto okHome
)
if exist "%CATALINA_HOME%\bin\%SERVICE_NAME%.exe" (
    set "EXECUTABLE=%CATALINA_HOME%\bin\%SERVICE_NAME%.exe"
    goto okHome
)
if "%DEFAULT_SERVICE_NAME%"== "%SERVICE_NAME%" (
    echo The file %DEFAULT_SERVICE_NAME%.exe was not found...
) else (
    echo Neither the %DEFAULT_SERVICE_NAME%.exe file nor the %SERVICE_NAME%.exe file was found...
)
echo Either the CATALINA_HOME environment variable is not defined correctly or
echo the incorrect service name has been used.
echo Both the CATALINA_HOME environment variable and the correct service name
echo are required to run this program.
exit /b 1
:okHome
cd "%CURRENT_DIR%"

rem Make sure prerequisite environment variables are set
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 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 noJavaHomeAsJre
rem Use JAVA_HOME as JRE_HOME
set "JRE_HOME=%JAVA_HOME%"
goto okJava

:preJava9Layout
rem Use JAVA_HOME\jre as JRE_HOME
set "JRE_HOME=%JAVA_HOME%\jre"
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
exit /b 1

:okJava
if not "%CATALINA_BASE%" == "" goto gotBase
set "CATALINA_BASE=%CATALINA_HOME%"

: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
rem or CATALINA_HOME/endorsed exists.
set ENDORSED_PROP=ignore.endorsed.dirs
if "%JAVA_ENDORSED_DIRS%" == "" goto noEndorsedVar
set ENDORSED_PROP=java.endorsed.dirs
goto doneEndorsed
:noEndorsedVar
if not exist "%CATALINA_HOME%\endorsed" goto doneEndorsed
set ENDORSED_PROP=java.endorsed.dirs
:doneEndorsed

rem Process the requested command
if /i %SERVICE_CMD% == install goto doInstall
if /i %SERVICE_CMD% == remove goto doRemove
if /i %SERVICE_CMD% == uninstall goto doRemove
echo Unknown parameter "%SERVICE_CMD%"
:displayUsage
echo.
echo Usage: service.bat install/remove [service_name [--rename]] [--user username]
exit /b 1

:doRemove
rem Remove the service
echo Removing the service '%SERVICE_NAME%' ...
echo Using CATALINA_BASE:    "%CATALINA_BASE%"

"%EXECUTABLE%" //DS//%SERVICE_NAME% ^
    --LogPath "%CATALINA_BASE%\logs"
if not errorlevel 1 goto removed
echo Failed removing '%SERVICE_NAME%' service
exit /b 1
:removed
echo The service '%SERVICE_NAME%' has been removed
if exist "%CATALINA_HOME%\bin\%SERVICE_NAME%.exe" (
    rename "%SERVICE_NAME%.exe" "%DEFAULT_SERVICE_NAME%.exe"
    rename "%SERVICE_NAME%w.exe" "%DEFAULT_SERVICE_NAME%w.exe"
)
exit /b 0

:doInstall
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
set "JVM=%JRE_HOME%\bin\server\jvm.dll"
if exist "%JVM%" goto foundJvm
rem Try to use the client jvm
set "JVM=%JRE_HOME%\bin\client\jvm.dll"
if exist "%JVM%" goto foundJvm
echo Warning: Neither 'server' nor 'client' jvm.dll was found at JRE_HOME.
set JVM=auto
:foundJvm
echo Using JVM:              "%JVM%"

set "CLASSPATH=%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_BASE%\bin\tomcat-juli.jar"
if not "%CATALINA_HOME%" == "%CATALINA_BASE%" set "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\tomcat-juli.jar"

if "%SERVICE_STARTUP_MODE%" == "" set SERVICE_STARTUP_MODE=manual
if "%JvmMs%" == "" set JvmMs=128
if "%JvmMx%" == "" set JvmMx=256

if exist "%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe" (
    if "x%RENAME%x" == "x--renamex" (
        rename "%DEFAULT_SERVICE_NAME%.exe" "%SERVICE_NAME%.exe"
        rename "%DEFAULT_SERVICE_NAME%w.exe" "%SERVICE_NAME%w.exe"
        set "EXECUTABLE=%CATALINA_HOME%\bin\%SERVICE_NAME%.exe"
    )
)

"%EXECUTABLE%" //IS//%SERVICE_NAME% ^
    --Description "Apache Tomcat 8.5.96 Server - https://tomcat.apache.org/" ^
    --DisplayName "%SERVICE_NAME%" ^
    --Install "%EXECUTABLE%" ^
    --LogPath "%CATALINA_BASE%\logs" ^
    --StdOutput auto ^
    --StdError auto ^
    --Classpath "%CLASSPATH%" ^
    --Jvm "%JVM%" ^
    --StartMode jvm ^
    --StopMode jvm ^
    --StartPath "%CATALINA_HOME%" ^
    --StopPath "%CATALINA_HOME%" ^
    --StartClass org.apache.catalina.startup.Bootstrap ^
    --StopClass org.apache.catalina.startup.Bootstrap ^
    --StartParams start ^
    --StopParams stop ^
    --JvmOptions "-Dcatalina.home=%CATALINA_HOME%;-Dcatalina.base=%CATALINA_BASE%;-D%ENDORSED_PROP%=%CATALINA_HOME%\endorsed;-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties;%JvmArgs%" ^
    --JvmOptions9 "--add-opens=java.base/java.lang=ALL-UNNAMED#--add-opens=java.base/java.io=ALL-UNNAMED#--add-opens=java.base/java.util=ALL-UNNAMED#--add-opens=java.base/java.util.concurrent=ALL-UNNAMED#--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED" ^
    --Startup "%SERVICE_STARTUP_MODE%" ^
    --JvmMs "%JvmMs%" ^
    --JvmMx "%JvmMx%"
if not errorlevel 1 goto installed
echo Failed installing '%SERVICE_NAME%' service
exit /b 1
:installed
echo The service '%SERVICE_NAME%' has been installed.
exit /b 0


Modified too service name:
Image
overdrive
 
Posts: 4
Joined: 29. March 2024 16:47
XAMPP version: 8.2.12
Operating System: Windows 11

Re: [Tomcat] Service was not installed

Postby overdrive » 01. April 2024 22:09

Hello friends. I have managed to get the activation/deactivation of the tomcat service to run correctly. Next, I am going to put the modified files and then the causes.

Files on root xampp:
  • xampp-control.ini: I have change security rights for all user because it cause Exception AccessViolation
    Image
  • xampp-control.ini: Change service tomcat name to Tomcat8 on section [ServicesNames]
  • catalina_service.bat:
    Code: Select all
    @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.

    if "%OS%" == "Windows_NT" setlocal
    rem ---------------------------------------------------------------------------
    rem NT Service Install/Uninstall script
    rem
    rem Options
    rem install                Install the service using Tomcat as service name.
    rem                        Service is installed using default settings.
    rem remove                 Remove the service from the System.
    rem
    rem name        (optional) If the second argument is present it is considered
    rem                        to be new service name
    rem
    rem $Id: service.bat 1000718 2010-09-24 06:00:00Z mturk $
    rem ---------------------------------------------------------------------------

    rem ---------XAMPP-------------------------------------------------------------
    ::::::::::::::::::::::::::::::::::::
    ::  Set JAVA_HOME or JRE_HOME     ::
    ::::::::::::::::::::::::::::::::::::

    echo.
    echo [XAMPP]: Searching for JDK or JRE HOME with reg query ...
    set JDKKeyName64=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK
    set JDKKeyName64Short=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK
    set AdoptOpenJDKKeyName64=HKEY_LOCAL_MACHINE\SOFTWARE\AdoptOpenJDK\JDK
    set JREKeyName64=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment
    set JREKeyName64Short=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JRE
    set AdoptOpenJDKKeyName64JRE=HKEY_LOCAL_MACHINE\SOFTWARE\AdoptOpenJDK\JRE
    set "Tomcat=tomcat8"

    reg query "%JDKKeyName64%" /s
    if %ERRORLEVEL% EQU 1 (
        echo . [XAMPP]: Could not find 32 bit or 64 bit JDK
        echo . [XAMPP]: Looking for 32 bit JDK on 64 bit machine
        goto FINDJDK64SHORT
    )
    set KeyName=%JDKKeyName64%
    goto JDKRUN

    :FINDJDK64SHORT
    reg query "%JDKKeyName64Short%" /s
    if %ERRORLEVEL% EQU  1 (
        echo . [XAMPP]: Could not find 32 bit JDK
        echo . [XAMPP]: Looking for 32 bit or 64 bit on 64 bit machine with short name
        goto FINDADOPTOPENJDK64
    )
    set KeyName=%JDKKeyName64Short%
    goto JDKRUN

    :FINDADOPTOPENJDK64
    reg query "%AdoptOpenJDKKeyName64%" /s
    if %ERRORLEVEL% EQU  1 (
        echo . [XAMPP]: Could not find 32 bit or 64 bit AdoptOpenJDK
        echo . [XAMPP]: Looking for 32 bit or 64 bit JRE
        goto FINDJRE64
    )
    set KeyName=%AdoptOpenJDKKeyName64%
    goto JDKRUN

    :FINDJRE64
    reg query "%JREKeyName64%" /s
    if %ERRORLEVEL% EQU 1 (
        echo . [XAMPP]: Could not find 32 bit or 64 bit JRE with long name
        echo . [XAMPP]: Looking for 32 bit or 64 bit JRE on 64 bit machine with short name
        goto FINDJRE64SHORT
    )
    set KeyName=%JREKeyName64%
    goto JRERUN

    :FINDJRE64SHORT
    reg query "%JREKeyName64Short%" /s
    if %ERRORLEVEL% EQU 1 (
        echo . [XAMPP]: Could not find 32 bit or 64 bit JRE with short name
        echo . [XAMPP]: Looking for 32 bit or 64 bit AdoptOpenJDK JRE on 64 bit machine
        goto FINDADOPTOPENJDK64JRE
    )
    set KeyName=%JREKeyName64Short%
    goto JRERUN

    :FINDADOPTOPENJDK64JRE
    reg query "%AdoptOpenJDKKeyName64JRE%" /s
    if %ERRORLEVEL% EQU  1 (
        echo . [XAMPP]: Could not find 32 bit or 64 bit AdoptOpenJDK JRE
        echo . [XAMPP]: Looking for 32 JRE on 64 bit machine
        goto ENDERROR
    )
    set KeyName=%AdoptOpenJDKKeyName64JRE%
    goto JDKRUN

    :JDKRUN
    echo.
    echo [XAMPP]: Using JDK
    set "CURRENT_DIR=%~dp0"
    set "CURRENT_DIR=%CURRENT_DIR:~,-1%"
    set "CATALINA_HOME=%CURRENT_DIR%\tomcat"

    set Cmd=reg query "%KeyName%" /s
    for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JAVA_HOME=%%j

    echo.
    echo [XAMPP]: Seems fine!
    echo [XAMPP]: Set JAVA_HOME : %JAVA_HOME%
    echo [XAMPP]: Set CATALINA_HOME : %CATALINA_HOME%
    echo.
    goto NEXT

    :JRERUN
    echo.
    echo [XAMPP]: Using JRE
    set "CURRENT_DIR=%~dp0"
    set "CURRENT_DIR=%CURRENT_DIR:~,-1%"
    set "CATALINA_HOME=%CURRENT_DIR%\tomcat"

    set Cmd=reg query "%KeyName%" /s
    for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JRE_HOME=%%j

    echo.
    echo [XAMPP]: Seems fine!
    echo [XAMPP]: Set JRE_HOME : %JRE_HOME%
    echo [XAMPP]: Set CATALINA_HOME : %CATALINA_HOME%
    echo.
    goto NEXT

    :ENDERROR
    exit 1

    :NEXT

    echo [XAMPP]: Finding Java Version

    set Cmd=reg query "%KeyName%" /v CurrentVersion
    for /f "tokens=2*" %%i in ('%Cmd% ^| find "CurrentVersion"') do set CVERSION=%%j

    echo [XAMPP]: Java Version: %CVERSION%
    echo [XAMPP]: Starting Tomcat Service Install...
    echo .

    rem ----------END XAMPP-----------------------------------------------------------------

    set "SELF=%~dp0%service.bat"
    rem Guess CATALINA_HOME if not defined
    set "CURRENT_DIR=%~dp0"
    set "CURRENT_DIR=%CURRENT_DIR:~,-1%"
    if not "%CATALINA_HOME%" == "" goto gotHome
    set "CATALINA_HOME=%cd%"
    if exist "%CATALINA_HOME%\bin\%Tomcat%.exe" goto okHome
    rem CD to the upper dir
    cd ..
    set "CATALINA_HOME=%cd%"
    :gotHome
    if exist "%CATALINA_HOME%\bin\%Tomcat%.exe" goto okHome
    echo The tomcat.exe was not found...
    echo The CATALINA_HOME environment variable is not defined correctly.
    echo This environment variable is needed to run this program
    goto end
    :okHome
    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%\bin\java.exe" goto noJavaHome
    if not exist "%JAVA_HOME%\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%"
    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
    if not "%CATALINA_BASE%" == "" goto gotBase
    set "CATALINA_BASE=%CATALINA_HOME%"
    :gotBase

    set "EXECUTABLE=%CATALINA_HOME%\bin\%Tomcat%.exe"

    rem Set default Service name
    set SERVICE_NAME=%Tomcat%
    set PR_DISPLAYNAME=Apache Tomcat

    if "x%1x" == "xx" goto displayUsage
    set SERVICE_CMD=%1
    shift
    if "x%1x" == "xx" goto checkServiceCmd
    :checkUser
    if "x%1x" == "x/userx" goto runAsUser
    if "x%1x" == "x--userx" goto runAsUser
    set SERVICE_NAME=%1
    set PR_DISPLAYNAME=Apache Tomcat %1
    shift
    if "x%1x" == "xx" goto checkServiceCmd
    goto checkUser
    :runAsUser
    shift
    if "x%1x" == "xx" goto displayUsage
    set SERVICE_USER=%1
    shift
    runas /env /savecred /user:%SERVICE_USER% "%COMSPEC% /K \"%SELF%\" %SERVICE_CMD% %SERVICE_NAME%"
    goto end
    :checkServiceCmd
    if /i %SERVICE_CMD% == install goto doInstall
    if /i %SERVICE_CMD% == remove goto doRemove
    if /i %SERVICE_CMD% == uninstall goto doRemove
    echo Unknown parameter "%1"
    :displayUsage
    echo.
    echo Usage: service.bat install/remove [service_name] [/user username]
    goto end

    :doRemove
    rem Remove the service
    "%EXECUTABLE%" //DS//%SERVICE_NAME%
    if not errorlevel 1 goto removed
    echo Failed removing '%SERVICE_NAME%' service
    goto end
    :removed
    echo The service '%SERVICE_NAME%' has been removed
    goto end

    :doInstall
    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 Use the environment variables as an example
    rem Each command line option is prefixed with PR_

    set PR_DESCRIPTION=Apache Tomcat Server - http://tomcat.apache.org/
    set "PR_INSTALL=%EXECUTABLE%"
    set "PR_LOGPATH=%CATALINA_BASE%\logs"
    set "PR_CLASSPATH=%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_BASE%\bin\tomcat-juli.jar;%CATALINA_HOME%\bin\tomcat-juli.jar"
    rem Set the server jvm from JAVA_HOME
    set "PR_JVM=%JRE_HOME%\bin\server\jvm.dll"
    if exist "%PR_JVM%" goto foundJvm
    rem Set the client jvm from JAVA_HOME
    set "PR_JVM=%JRE_HOME%\bin\client\jvm.dll"
    if exist "%PR_JVM%" goto foundJvm
    set PR_JVM=auto
    :foundJvm
    echo Using JVM:              "%PR_JVM%"
    "%EXECUTABLE%" //IS//%SERVICE_NAME% --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop --Startup auto
    if not errorlevel 1 goto installed
    echo Failed installing '%SERVICE_NAME%' service
    goto ENDERROR
    :installed
    rem Clear the environment variables. They are not needed any more.
    set PR_DISPLAYNAME=
    set PR_DESCRIPTION=
    set PR_INSTALL=
    set PR_LOGPATH=
    set PR_CLASSPATH=
    set PR_JVM=
    rem Set extra parameters
    "%EXECUTABLE%" //US//%SERVICE_NAME% --JvmOptions "-Dcatalina.base=%CATALINA_BASE%;-Dcatalina.home=%CATALINA_HOME%;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed" --StartMode jvm --StopMode jvm
    rem More extra parameters
    set "PR_LOGPATH=%CATALINA_BASE%\logs"
    set PR_STDOUTPUT=auto
    set PR_STDERROR=auto

    rem XAMPP: We need special parameters for Java 7
    if "%CVERSION%" == "1.7" goto JAVA7
    :JAVA
    "%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties" --JvmMs 128 --JvmMx 256
    goto FINISH
    :JAVA7
    "%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties;-Djava.net.preferIPv4Stack=true" --JvmMs 128 --JvmMx 256
    :FINISH
    echo The service '%SERVICE_NAME%' has been installed.

    :end
    cd "%CURRENT_DIR%"


  • catalina_start.bat
    Code: Select all
    @echo off
    SetLocal EnableDelayedExpansion
    cd /D %~dp0
    ::::::::::::::::::::::::::::::::::::
    ::  Set JAVA_HOME or JRE_HOME     ::
    ::::::::::::::::::::::::::::::::::::
    title %~0

    IF EXIST tomcat\logs\catalina.pid (
        del /F/Q tomcat\logs\catalina.pid
    )

    set TASKCMD=TASKLIST /V
    set FINDCMD=FIND /I

    FOR /F "tokens=2 delims= " %%A IN ('%TASKCMD% ^| %FINDCMD% "%~0"') DO SET MyPID=%%A

    echo.
    echo [XAMPP]: Searching for JDK or JRE HOME with reg query ...
    set JDKKeyName64=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK
    set JDKKeyName64Short=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK
    set AdoptOpenJDKKeyName64=HKEY_LOCAL_MACHINE\SOFTWARE\AdoptOpenJDK\JDK
    set JREKeyName64=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment
    set JREKeyName64Short=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JRE
    set AdoptOpenJDKKeyName64JRE=HKEY_LOCAL_MACHINE\SOFTWARE\AdoptOpenJDK\JRE

    reg query "%JDKKeyName64%" /s
    if %ERRORLEVEL% EQU 1 (
        echo . [XAMPP]: Could not find 32 bit or 64 bit JDK
        echo . [XAMPP]: Looking for 32 bit JDK on 64 bit machine
        goto FINDJDK64SHORT
    )
    set KeyName=%JDKKeyName64%
    goto JDKRUN

    :FINDJDK64SHORT
    reg query "%JDKKeyName64Short%" /s
    if %ERRORLEVEL% EQU  1 (
        echo . [XAMPP]: Could not find 32 bit JDK
        echo . [XAMPP]: Looking for 32 bit or 64 bit on 64 bit machine with short name
        goto FINDADOPTOPENJDK64
    )
    set KeyName=%JDKKeyName64Short%
    goto JDKRUN

    :FINDADOPTOPENJDK64
    reg query "%AdoptOpenJDKKeyName64%" /s
    if %ERRORLEVEL% EQU  1 (
        echo . [XAMPP]: Could not find 32 bit or 64 bit AdoptOpenJDK
        echo . [XAMPP]: Looking for 32 bit or 64 bit JRE
        goto FINDJRE64
    )
    set KeyName=%AdoptOpenJDKKeyName64%
    goto JDKRUN

    :FINDJRE64
    reg query "%JREKeyName64%" /s
    if %ERRORLEVEL% EQU 1 (
        echo . [XAMPP]: Could not find 32 bit or 64 bit JRE with long name
        echo . [XAMPP]: Looking for 32 bit or 64 bit JRE on 64 bit machine with short name
        goto FINDJRE64SHORT
    )
    set KeyName=%JREKeyName64%
    goto JRERUN

    :FINDJRE64SHORT
    reg query "%JREKeyName64Short%" /s
    if %ERRORLEVEL% EQU 1 (
        echo . [XAMPP]: Could not find 32 bit or 64 bit JRE with short name
        echo . [XAMPP]: Looking for 32 bit or 64 bit AdoptOpenJDK JRE on 64 bit machine
        goto FINDADOPTOPENJDK64JRE
    )
    set KeyName=%JREKeyName64Short%
    goto JRERUN

    :FINDADOPTOPENJDK64JRE
    reg query "%AdoptOpenJDKKeyName64JRE%" /s
    if %ERRORLEVEL% EQU  1 (
        echo . [XAMPP]: Could not find 32 bit or 64 bit AdoptOpenJDK JRE
        echo . [XAMPP]: Looking for 32 JRE on 64 bit machine
        goto ENDERROR
    )
    set KeyName=%AdoptOpenJDKKeyName64JRE%
    goto JDKRUN

    :JDKRUN
    echo.
    echo [XAMPP]: Using JDK
    set "CURRENT_DIR=%~dp0"
    set "CURRENT_DIR=%CURRENT_DIR:~,-1%"
    set "CATALINA_HOME=%CURRENT_DIR%\tomcat"

    if NOT DEFINED JAVA_HOME (
        set Cmd=reg query "!KeyName!" /s
        for /f "tokens=2*" %%i in ('!Cmd! ^| find "JavaHome"') do set JAVA_HOME=%%j
    )

    echo.
    echo [XAMPP]: Seems fine!
    echo [XAMPP]: Set JAVA_HOME : %JAVA_HOME%
    echo [XAMPP]: Set CATALINA_HOME : %CATALINA_HOME%
    echo.

    if %ERRORLEVEL% == 0 (
        echo %MyPID% > tomcat\logs\catalina.pid
    )

    "%CATALINA_HOME%\bin\catalina.bat" run
    goto END

    :JRERUN
    echo.
    echo [XAMPP]: Using JRE
    set "CURRENT_DIR=%~dp0"
    set "CURRENT_DIR=%CURRENT_DIR:~,-1%"
    set "CATALINA_HOME=%CURRENT_DIR%\tomcat"

    if NOT DEFINED JRE_HOME (
        set Cmd=reg query "!KeyName!" /s
        for /f "tokens=2*" %%i in ('!Cmd! ^| find "JavaHome"') do set JRE_HOME=%%j
    )

    echo.
    echo [XAMPP]: Seems fine!
    echo [XAMPP]: Set JRE_HOME : %JRE_HOME%
    echo [XAMPP]: Set CATALINA_HOME : %CATALINA_HOME%
    echo.

    if %ERRORLEVEL% == 0 (
        echo %MyPID% > tomcat\logs\catalina.pid
    )

    "%CATALINA_HOME%\bin\catalina.bat" run
    goto END

    :ENDERROR
    exit 1

    :END
    echo done.
    SetLocal DisableDelayedExpansion
    pause



  • catalina_stop.bat
    Code: Select all
    @echo off
    SetLocal EnableDelayedExpansion
    cd /D %~dp0
    ::::::::::::::::::::::::::::::::::::
    ::  Set JAVA_HOME or JRE_HOME     ::
    ::::::::::::::::::::::::::::::::::::
    title %~0

    echo.
    echo [XAMPP]: Searching for JDK or JRE HOME with reg query ...
    set JDKKeyName64=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK
    set JDKKeyName64Short=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK
    set AdoptOpenJDKKeyName64=HKEY_LOCAL_MACHINE\SOFTWARE\AdoptOpenJDK\JDK
    set JREKeyName64=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment
    set JREKeyName64Short=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JRE
    set AdoptOpenJDKKeyName64JRE=HKEY_LOCAL_MACHINE\SOFTWARE\AdoptOpenJDK\JRE

    reg query "%JDKKeyName64%" /s
    if %ERRORLEVEL% EQU 1 (
        echo . [XAMPP]: Could not find 32 bit or 64 bit JDK
        echo . [XAMPP]: Looking for 32 bit JDK on 64 bit machine
        goto FINDJDK64SHORT
    )
    set KeyName=%JDKKeyName64%
    goto JDKRUN

    :FINDJDK64SHORT
    reg query "%JDKKeyName64Short%" /s
    if %ERRORLEVEL% EQU  1 (
        echo . [XAMPP]: Could not find 32 bit JDK
        echo . [XAMPP]: Looking for 32 bit or 64 bit on 64 bit machine with short name
        goto FINDADOPTOPENJDK64
    )
    set KeyName=%JDKKeyName64Short%
    goto JDKRUN

    :FINDADOPTOPENJDK64
    reg query "%AdoptOpenJDKKeyName64%" /s
    if %ERRORLEVEL% EQU  1 (
        echo . [XAMPP]: Could not find 32 bit or 64 bit AdoptOpenJDK
        echo . [XAMPP]: Looking for 32 bit or 64 bit JRE
        goto FINDJRE64
    )
    set KeyName=%AdoptOpenJDKKeyName64%
    goto JDKRUN

    :FINDJRE64
    reg query "%JREKeyName64%" /s
    if %ERRORLEVEL% EQU 1 (
        echo . [XAMPP]: Could not find 32 bit or 64 bit JRE with long name
        echo . [XAMPP]: Looking for 32 bit or 64 bit JRE on 64 bit machine with short name
        goto FINDJRE64SHORT
    )
    set KeyName=%JREKeyName64%
    goto JRERUN

    :FINDJRE64SHORT
    reg query "%JREKeyName64Short%" /s
    if %ERRORLEVEL% EQU 1 (
        echo . [XAMPP]: Could not find 32 bit or 64 bit JRE with short name
        echo . [XAMPP]: Looking for 32 bit or 64 bit AdoptOpenJDK JRE on 64 bit machine
        goto FINDADOPTOPENJDK64JRE
    )
    set KeyName=%JREKeyName64Short%
    goto JRERUN

    :FINDADOPTOPENJDK64JRE
    reg query "%AdoptOpenJDKKeyName64JRE%" /s
    if %ERRORLEVEL% EQU  1 (
        echo . [XAMPP]: Could not find 32 bit or 64 bit AdoptOpenJDK JRE
        echo . [XAMPP]: Looking for 32 JRE on 64 bit machine
        goto ENDERROR
    )
    set KeyName=%AdoptOpenJDKKeyName64JRE%
    goto JDKRUN

    :JDKRUN
    echo.
    echo [XAMPP]: Using JDK
    set "CURRENT_DIR=%~dp0"
    set "CURRENT_DIR=%CURRENT_DIR:~,-1%"
    set "CATALINA_HOME=%CURRENT_DIR%\tomcat"

    if NOT DEFINED JAVA_HOME (
        set Cmd=reg query "!KeyName!" /s
        for /f "tokens=2*" %%i in ('!Cmd! ^| find "JavaHome"') do set JAVA_HOME=%%j
    )

    echo.
    echo [XAMPP]: Seems fine!
    echo [XAMPP]: Set JAVA_HOME : %JAVA_HOME%
    echo [XAMPP]: Set CATALINA_HOME : %CATALINA_HOME%
    echo.

    if %ERRORLEVEL% == 0 (
        del /F/Q tomcat\logs\catalina.pid
    )

    "%CATALINA_HOME%\bin\catalina.bat" stop
    goto END

    :JRERUN
    echo.
    echo [XAMPP]: Using JRE
    set "CURRENT_DIR=%~dp0"
    set "CURRENT_DIR=%CURRENT_DIR:~,-1%"
    set "CATALINA_HOME=%CURRENT_DIR%\tomcat"

    if NOT DEFINED JRE_HOME (
        set Cmd=reg query "!KeyName!" /s
        for /f "tokens=2*" %%i in ('!Cmd! ^| find "JavaHome"') do set JRE_HOME=%%j
    )

    echo.
    echo [XAMPP]: Seems fine!
    echo [XAMPP]: Set JRE_HOME : %JRE_HOME%
    echo [XAMPP]: Set CATALINA_HOME : %CATALINA_HOME%
    echo.

    if %ERRORLEVEL% == 0 (
        del /F/Q tomcat\logs\catalina.pid
    )

    "%CATALINA_HOME%\bin\catalina.bat" stop
    goto END

    :ENDERROR
    exit 1

    :END
    echo done.
    SetLocal DisableDelayedExpansion

Files on xampp/tomcat

  • catalina_start.bat
    Code: Select all
    @echo off
    ::::::::::::::::::::::::::::::::::::
    ::  Set JAVA_HOME and   ::
    ::::::::::::::::::::::::::::::::::::

    IF EXIST tomcat\logs\catalina.pid (
      del /F/Q tomcat\logs\catalina.pid
    )

    echo.
    echo [XAMPP]: Searching JDK HOME with reg query ...
    set KeyName=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK

    reg query "%KeyName%" /s
    if %ERRORLEVEL% == 1 (
      echo . [XAMPP]: Cannot find current JDK installation!
      echo . [XAMPP]: Cannot set JAVA_HOME. Aborting ...
      goto :END
    )

    set "CURRENT_DIR=%~dp0"
    set "CURRENT_DIR=%CURRENT_DIR:~,-1%"
    set "CATALINA_HOME=%CURRENT_DIR%"

    :: only for windows 32 bit if you have problems with the tcnative-1.dll
    :: set CATALINA_OPTS=-Djava.library.path="%CATALINA_HOME%\bin"

    set Cmd=reg query "%KeyName%" /s
    for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JAVA_HOME=%%j

    echo.
    echo [XAMPP]: Seems fine!
    echo [XAMPP]: Set JAVA_HOME : %JAVA_HOME%
    echo [XAMPP]: Set CATALINA_HOME : %CATALINA_HOME%
    echo.

    if %ERRORLEVEL% == 0 (
    echo run > logs\catalina.pid
    )

    "%CATALINA_HOME%\bin\catalina.bat" run


    :END
    echo done.
    pause
  • catalina_stop.bat
    Code: Select all
    @echo off
    ::::::::::::::::::::::::::::::::::::
    ::  Set JAVA_HOME and   ::
    ::::::::::::::::::::::::::::::::::::


    echo.
    echo [XAMPP]: Searching JDK HOME with reg query ...
    set KeyName=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK

    reg query "%KeyName%" /s
    if %ERRORLEVEL% == 1 (
      echo . [XAMPP]: Cannot find current JDK installation!
      echo . [XAMPP]: Cannot set JAVA_HOME. Aborting ...
      goto :END
    )

    set "CURRENT_DIR=%~dp0"
    set "CURRENT_DIR=%CURRENT_DIR:~,-1%"
    set "CATALINA_HOME=%CURRENT_DIR%"

    set Cmd=reg query "%KeyName%" /s
    for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JAVA_HOME=%%j

    echo.
    echo [XAMPP]: Seems fine!
    echo [XAMPP]: Using JAVA_HOME : %JAVA_HOME%
    echo [XAMPP]: Using CATALINA_HOME : %CATALINA_HOME%
    echo.

    if %ERRORLEVEL% == 0 {
    del /F/Q logs\catalina.pid
    }

    "%CATALINA_HOME%\bin\catalina.bat" stop


    :END
    echo done.
    pause
  • tomcat_service_install.bat
    Code: Select all
    @echo off

    if "%OS%" == "Windows_NT" goto WinNT

    :Win9X
    echo Don't be stupid! Win9x don't know Services
    goto exit

    :WinNT

    echo [XAMPP]: Searching JDK HOME with reg query ...
    set KeyName=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK

    reg query "%KeyName%" /s
    if %ERRORLEVEL% == 1 (
      echo . [XAMPP]: Cannot find current JDK installation!
      echo . [XAMPP]: Cannot set JAVA_HOME. Aborting ...
      goto :END
    )

    set "CURRENT_DIR=%~dp0"
    set "CURRENT_DIR=%CURRENT_DIR:~,-1%"
    set "CATALINA_HOME=%CURRENT_DIR%"

    set Cmd=reg query "%KeyName%" /s
    for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JAVA_HOME=%%j

    echo.
    echo [XAMPP]: Seems fine!
    echo [XAMPP]: Using %JAVA_HOME%
    echo.

    set JRE_HOME=%JAVA_HOME%

    echo [XAMPP]: Using JAVA_HOME=%JAVA_HOME%
    echo [XAMPP]: Using CATALINA_HOME=%CATALINA_HOME%
    echo [XAMPP]: Using JRE_HOME=%JRE_HOME%

    echo Installing Tomcat as an Service
    "%CURRENT_DIR%\bin\service.bat" install Tomcat8


    goto exit

    :END

    :exit

  • tomcat_service_uninstall.bat
    Code: Select all
    @echo off

    if "%OS%" == "Windows_NT" goto WinNT

    :Win9X
    echo Don't be stupid! Win9x don't know Services
    goto exit

    :WinNT

    echo [XAMPP]: Searching JDK HOME with reg query ...
    set KeyName=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK

    reg query "%KeyName%" /s
    if %ERRORLEVEL% == 1 (
      echo . [XAMPP]: Cannot find current JDK installation!
      echo . [XAMPP]: Cannot set JAVA_HOME. Aborting ...
      goto :END
    )

    set "CURRENT_DIR=%~dp0"
    set "CURRENT_DIR=%CURRENT_DIR:~,-1%"
    set "CATALINA_HOME=%CURRENT_DIR%"

    set Cmd=reg query "%KeyName%" /s
    for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JAVA_HOME=%%j

    echo.
    echo [XAMPP]: Seems fine!
    echo [XAMPP]: Using %JAVA_HOME%
    echo.
     
    set JRE_HOME=%JAVA_HOME%

    echo [XAMPP]: Using JAVA_HOME=%JAVA_HOME%
    echo [XAMPP]: Using CATALINA_HOME=%CATALINA_HOME%
    echo [XAMPP]: Using JRE_HOME=%JRE_HOME%

    echo Try to stop Tomcat7 service
    net stop Tomcat8
    echo Uninstall Tomcat as an Service
    "%CURRENT_DIR%\bin\service.bat" remove Tomcat8


    goto exit

    :END

    :exit

Files on xampp/tomcat/bin

Of that files I have changed entries that used of %cd% by:

set "CURRENT_DIR=%~dp0"
set "CURRENT_DIR=%CURRENT_DIR:~,-1%"


  • catalina.bat
  • ciphers.bat
  • configtest.bat
  • digest.bat
  • service.bat
  • shutdown.bat
  • startup.bat
  • tool-wrapper.bat
  • version.bat
  • catalina_start.bat
  • catalina_stop.bat
  • tomcat_service_install.bat
  • tomcat_service_uninstall.bat

In all bat files I have had to replace the use of the %cd% variable since in current versions of MSDOS it causes unexpected behavior, making it more appropriate to use:

set "CURRENT_DIR=%~dp0"
set "CURRENT_DIR=%CURRENT_DIR:~,-1%"

That has fixed quite a few bugs. In the xampp and xampp/tomcat root bats I have also had to modify the paths to the JDK since they still used old registry names for JRE1.8.

Perhaps it would be more appropriate to use setx to establish the classpaths, but that is for the developers to consider.

It wouldn't be a bad idea to rewrite the batch files from scratch since I've only patched it to work with JDK17, I haven't tested with JRE1.8.

Files changed: https://www.dropbox.com/scl/fi/ljeqwic5rvelu20zvfzsv/xampp_tomcat_files_fixed.zip?rlkey=by7j99z43b4ipx7e8s459biom&dl=0
overdrive
 
Posts: 4
Joined: 29. March 2024 16:47
XAMPP version: 8.2.12
Operating System: Windows 11

Re: [Tomcat] Service was not installed

Postby Altrea » 02. April 2024 18:55

Hi overdrive,

Thanks for all the time and effort you put into these.
I have downloaded your fixes and will take a look into these for sure.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11934
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: [Tomcat] Service was not installed

Postby overdrive » 02. April 2024 19:14

Hello, after doing lots of testing, I really only needed to modify the catalina_service.bat file. With this, the functionality of the create service button is recovered, however, it did not start the service.

A moment ago I stumbled upon the solution to start the service by chance, since I also carried out several tests at work.

And the only difference between my computer environment and my work environment is that in the latter I also have JRE8 installed and JDK17.

When I install JRE8 on my computer, the service starts. And I can create and delete the service. I don't know the dependency with JRE8 but if you only have one JDK installed it doesn't work.

Environment variables were well defined JAVA_HOME and path like %JAVA_HOME%\bin:
Image

Catalina_service.bat
Code: Select all
@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.

if "%OS%" == "Windows_NT" setlocal
rem ---------------------------------------------------------------------------
rem NT Service Install/Uninstall script
rem
rem Options
rem install                Install the service using Tomcat as service name.
rem                        Service is installed using default settings.
rem remove                 Remove the service from the System.
rem
rem name        (optional) If the second argument is present it is considered
rem                        to be new service name
rem
rem $Id: service.bat 1000718 2010-09-24 06:00:00Z mturk $
rem ---------------------------------------------------------------------------

rem ---------XAMPP-------------------------------------------------------------
::::::::::::::::::::::::::::::::::::
::  Set JAVA_HOME or JRE_HOME     ::
::::::::::::::::::::::::::::::::::::

echo.
echo [XAMPP]: Searching for JDK or JRE HOME with reg query ...
set JDKKeyName64=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit
set JDKKeyName64Short=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK
set AdoptOpenJDKKeyName64=HKEY_LOCAL_MACHINE\SOFTWARE\AdoptOpenJDK\JDK
set JREKeyName64=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment
set JREKeyName64Short=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JRE
set AdoptOpenJDKKeyName64JRE=HKEY_LOCAL_MACHINE\SOFTWARE\AdoptOpenJDK\JRE

reg query "%JDKKeyName64%" /s
if %ERRORLEVEL% EQU 1 (
    echo . [XAMPP]: Could not find 32 bit or 64 bit JDK
    echo . [XAMPP]: Looking for 32 bit JDK on 64 bit machine
    goto FINDJDK64SHORT
)
set KeyName=%JDKKeyName64%
goto JDKRUN

:FINDJDK64SHORT
reg query "%JDKKeyName64Short%" /s
if %ERRORLEVEL% EQU  1 (
    echo . [XAMPP]: Could not find 32 bit JDK
    echo . [XAMPP]: Looking for 32 bit or 64 bit on 64 bit machine with short name
    goto FINDADOPTOPENJDK64
)
set KeyName=%JDKKeyName64Short%
goto JDKRUN

:FINDADOPTOPENJDK64
reg query "%AdoptOpenJDKKeyName64%" /s
if %ERRORLEVEL% EQU  1 (
    echo . [XAMPP]: Could not find 32 bit or 64 bit AdoptOpenJDK
    echo . [XAMPP]: Looking for 32 bit or 64 bit JRE
    goto FINDJRE64
)
set KeyName=%AdoptOpenJDKKeyName64%
goto JDKRUN

:FINDJRE64
reg query "%JREKeyName64%" /s
if %ERRORLEVEL% EQU 1 (
    echo . [XAMPP]: Could not find 32 bit or 64 bit JRE with long name
    echo . [XAMPP]: Looking for 32 bit or 64 bit JRE on 64 bit machine with short name
    goto FINDJRE64SHORT
)
set KeyName=%JREKeyName64%
goto JRERUN

:FINDJRE64SHORT
reg query "%JREKeyName64Short%" /s
if %ERRORLEVEL% EQU 1 (
    echo . [XAMPP]: Could not find 32 bit or 64 bit JRE with short name
    echo . [XAMPP]: Looking for 32 bit or 64 bit AdoptOpenJDK JRE on 64 bit machine
    goto FINDADOPTOPENJDK64JRE
)
set KeyName=%JREKeyName64Short%
goto JRERUN

:FINDADOPTOPENJDK64JRE
reg query "%AdoptOpenJDKKeyName64JRE%" /s
if %ERRORLEVEL% EQU  1 (
    echo . [XAMPP]: Could not find 32 bit or 64 bit AdoptOpenJDK JRE
    echo . [XAMPP]: Looking for 32 JRE on 64 bit machine
    goto ENDERROR
)
set KeyName=%AdoptOpenJDKKeyName64JRE%
goto JDKRUN

:JDKRUN
echo.
echo [XAMPP]: Using JDK
set "CURRENT_DIR=%~dp0"
set "CURRENT_DIR=%CURRENT_DIR:~,-1%"
set "CATALINA_HOME=%CURRENT_DIR%\tomcat"

set Cmd=reg query "%KeyName%" /s
for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JAVA_HOME=%%j

echo.
echo [XAMPP]: Seems fine!
echo [XAMPP]: Set JAVA_HOME : %JAVA_HOME%
echo [XAMPP]: Set CATALINA_HOME : %CATALINA_HOME%
echo.
goto NEXT

:JRERUN
echo.
echo [XAMPP]: Using JRE
set "CURRENT_DIR=%~dp0"
set "CURRENT_DIR=%CURRENT_DIR:~,-1%"
set "CATALINA_HOME=%CURRENT_DIR%\tomcat"

set Cmd=reg query "%KeyName%" /s
for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JRE_HOME=%%j

echo.
echo [XAMPP]: Seems fine!
echo [XAMPP]: Set JRE_HOME : %JRE_HOME%
echo [XAMPP]: Set CATALINA_HOME : %CATALINA_HOME%
echo.
goto NEXT

:ENDERROR
exit 1

:NEXT

echo [XAMPP]: Finding Java Version

set Cmd=reg query "%KeyName%" /v CurrentVersion
for /f "tokens=2*" %%i in ('%Cmd% ^| find "CurrentVersion"') do set CVERSION=%%j

echo [XAMPP]: Java Version: %CVERSION%
echo [XAMPP]: Starting Tomcat Service Install...
echo .

rem ----------END XAMPP-----------------------------------------------------------------

set "SELF=%~dp0%service.bat"
rem Guess CATALINA_HOME if not defined
set "CURRENT_DIR=%~dp0"
set "CURRENT_DIR=%CURRENT_DIR:~,-1%"
if not "%CATALINA_HOME%" == "" goto gotHome
set "CATALINA_HOME=%CURRENT_DIR%\tomcat"
if exist "%CATALINA_HOME%\bin\tomcat8.exe" goto okHome
rem CD to the upper dir
cd ..
set "CATALINA_HOME=%CURRENT_DIR%\tomcat"
:gotHome
if exist "%CATALINA_HOME%\bin\tomcat8.exe" goto okHome
echo The tomcat.exe was not found...
echo The CATALINA_HOME environment variable is not defined correctly.
echo This environment variable is needed to run this program
goto end
:okHome
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%\bin\java.exe" goto noJavaHome
if not exist "%JAVA_HOME%\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%\bin"
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
if not "%CATALINA_BASE%" == "" goto gotBase
set "CATALINA_BASE=%CATALINA_HOME%"
:gotBase

set "EXECUTABLE=%CATALINA_HOME%\bin\tomcat8.exe"

rem Set default Service name
set SERVICE_NAME=Tomcat
set PR_DISPLAYNAME=Apache Tomcat

if "x%1x" == "xx" goto displayUsage
set SERVICE_CMD=%1
shift
if "x%1x" == "xx" goto checkServiceCmd
:checkUser
if "x%1x" == "x/userx" goto runAsUser
if "x%1x" == "x--userx" goto runAsUser
set SERVICE_NAME=%1
set PR_DISPLAYNAME=Apache Tomcat %1
shift
if "x%1x" == "xx" goto checkServiceCmd
goto checkUser
:runAsUser
shift
if "x%1x" == "xx" goto displayUsage
set SERVICE_USER=%1
shift
runas /env /savecred /user:%SERVICE_USER% "%COMSPEC% /K \"%SELF%\" %SERVICE_CMD% %SERVICE_NAME%"
goto end
:checkServiceCmd
if /i %SERVICE_CMD% == install goto doInstall
if /i %SERVICE_CMD% == remove goto doRemove
if /i %SERVICE_CMD% == uninstall goto doRemove
echo Unknown parameter "%1"
:displayUsage
echo.
echo Usage: service.bat install/remove [service_name] [/user username]
goto end

:doRemove
rem Remove the service
"%EXECUTABLE%" //DS//%SERVICE_NAME%
if not errorlevel 1 goto removed
echo Failed removing '%SERVICE_NAME%' service
goto end
:removed
echo The service '%SERVICE_NAME%' has been removed
goto end

:doInstall
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 Use the environment variables as an example
rem Each command line option is prefixed with PR_

set PR_DESCRIPTION=Apache Tomcat Server - http://tomcat.apache.org/
set "PR_INSTALL=%EXECUTABLE%"
set "PR_LOGPATH=%CATALINA_BASE%\logs"
set "PR_CLASSPATH=%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_BASE%\bin\tomcat-juli.jar;%CATALINA_HOME%\bin\tomcat-juli.jar"
rem Set the server jvm from JAVA_HOME
set "PR_JVM=%JRE_HOME%\bin\server\jvm.dll"
if exist "%PR_JVM%" goto foundJvm
rem Set the client jvm from JAVA_HOME
set "PR_JVM=%JRE_HOME%\bin\client\jvm.dll"
if exist "%PR_JVM%" goto foundJvm
set PR_JVM=auto
:foundJvm
echo Using JVM:              "%PR_JVM%"
"%EXECUTABLE%" //IS//%SERVICE_NAME% --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop --Startup auto
if not errorlevel 1 goto installed
echo Failed installing '%SERVICE_NAME%' service
goto ENDERROR
:installed
rem Clear the environment variables. They are not needed any more.
set PR_DISPLAYNAME=
set PR_DESCRIPTION=
set PR_INSTALL=
set PR_LOGPATH=
set PR_CLASSPATH=
set PR_JVM=
rem Set extra parameters
"%EXECUTABLE%" //US//%SERVICE_NAME% --JvmOptions "-Dcatalina.base=%CATALINA_BASE%;-Dcatalina.home=%CATALINA_HOME%;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed" --StartMode jvm --StopMode jvm
rem More extra parameters
set "PR_LOGPATH=%CATALINA_BASE%\logs"
set PR_STDOUTPUT=auto
set PR_STDERROR=auto

rem XAMPP: We need special parameters for Java 7
if "%CVERSION%" == "1.7" goto JAVA7
:JAVA
"%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties" --JvmMs 128 --JvmMx 256
goto FINISH
:JAVA7
"%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties;-Djava.net.preferIPv4Stack=true" --JvmMs 128 --JvmMx 256
:FINISH
echo The service '%SERVICE_NAME%' has been installed.

:end
cd "%CURRENT_DIR%"



Code: Select all
https://youtu.be/zpmZ_-EIG00


I'm glad I got it to work because the tool is very useful and I needed it for an internship. I don't know if the dependency could be eliminated with JRE8.

King regards.
overdrive
 
Posts: 4
Joined: 29. March 2024 16:47
XAMPP version: 8.2.12
Operating System: Windows 11


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 181 guests