Installation Tomcat Windows

De EjnTricks

L'installation de Tomcat sous Windows est relativement simple et peut s'effectuer de deux manières:

  • Utilisation d'un binaire d'installation.
  • Décompression d'une archive.

La seconde méthode est recommandée dans le cadre de l'installation pour du développement. En effet, il sera très facile de paramétrer l'instance mise en place, de la démarrer / arrêter sans passer par la gestion des services. De plus, la première méthode a la facheuse tendance à modifier la base de registre.


Hand-icon.png Votre avis

Current user rating: 84/100 (1 votes)

 You need to enable JavaScript to vote


System-Install-icon.png Installation

Download-icon.png Téléchargement

Les archives sont téléchargeables depuis le officiel de Tomcat. Dans le cadre de cet article, l'archive pour la version 6 et 7 sont téléchargées.

Unzip-icon.png Mise en place

Il est possible de décompresser les archives n'importe où. Cependant, dans le cadre d'une multi installation, comme dans le cadre de cet article, il est important d'organiser les binaires. Une bonne pratique est de créer un répertoire Apps/Tomcat, par exemple c:/Apps/Tomcat, dans lequel seront décompressées les instances dans un répertoire portant le nom de la version:


Dans le cadre de cette copie d'écran, les version 4.1.18, 6.0.26, 6.0.37 x64 et 7.0.47 x64 sont "installées".


Run-icon.png Exécution

Les scripts d'exécution de Tomcat se situe dans le sous répertoire bin, dont le contenu est:

c:\>dir c:\Apps\Tomcat\7.0.47_x64\bin
 Le volume dans le lecteur C s'appelle OS
 Le numéro de série du volume est 749D-45FE

 Répertoire de c:\Apps\Tomcat\7.0.47_x64\bin

02/01/2014  23:01    <REP>          .
02/01/2014  23:01    <REP>          ..
01/01/2014  23:57            28 641 bootstrap.jar
01/01/2014  23:57             2 168 catalina-tasks.xml
01/01/2014  23:57            13 217 catalina.bat
01/01/2014  23:57            20 483 catalina.sh
01/01/2014  23:57           204 944 commons-daemon-native.tar.gz
01/01/2014  23:57            24 283 commons-daemon.jar
01/01/2014  23:57             2 131 configtest.bat
01/01/2014  23:57             1 982 configtest.sh
01/01/2014  23:57             1 342 cpappend.bat
01/01/2014  23:57             7 940 daemon.sh
01/01/2014  23:57             2 178 digest.bat
01/01/2014  23:57             2 021 digest.sh
01/01/2014  23:57             6 338 service.bat
01/01/2014  23:57             3 264 setclasspath.bat
01/01/2014  23:57             3 524 setclasspath.sh
01/01/2014  23:57             2 111 shutdown.bat
01/01/2014  23:57             1 960 shutdown.sh
01/01/2014  23:57             2 112 startup.bat
01/01/2014  23:57             1 961 startup.sh
01/01/2014  23:57         1 589 760 tcnative-1.dll
01/01/2014  23:57            38 682 tomcat-juli.jar
01/01/2014  23:57           286 622 tomcat-native.tar.gz
01/01/2014  23:57           103 936 tomcat7.exe
01/01/2014  23:57           104 448 tomcat7w.exe
01/01/2014  23:57             4 114 tool-wrapper.bat
01/01/2014  23:57             5 086 tool-wrapper.sh
01/01/2014  23:57             2 116 version.bat
01/01/2014  23:57             1 965 version.sh
              28 fichier(s)        2 469 329 octets
               2 Rép(s)  207 988 187 136 octets libres

Dans le cadre de ce paragraphe, il est supposé que la variable d'environnement JAVA_HOME est configurée avec la valeur C:\Apps\Java\jdk1.6.0_33_x64.

Start-icon.png Démarrage

Le démarrage du serveur s'effectue simplement en exécutant le script startup.bat. Ce script sera étudié dans le chapitre suivant.

c:\Apps\Tomcat\7.0.47_x64\bin>startup.bat
Using CATALINA_BASE:   "c:\Apps\Tomcat\7.0.47_x64"
Using CATALINA_HOME:   "c:\Apps\Tomcat\7.0.47_x64"
Using CATALINA_TMPDIR: "c:\Apps\Tomcat\7.0.47_x64\temp"
Using JRE_HOME:        "C:\Apps\Java\jdk1.6.0_33_x64"
Using CLASSPATH:       "c:\Apps\Tomcat\7.0.47_x64\bin\bootstrap.jar;c:\Apps\Tomcat\7.0.47_x64\bin\tomcat-juli.jar"
c:\Apps\Tomcat\7.0.47_x64\bin>

Et une nouvelle fenêtre est affichées avec les informations de démarrage. En fonction des applications mises à disposition, le contenu des message peut être différent:

2 janv. 2014 23:06:13 org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.29 using APR version 1.4.8.
2 janv. 2014 23:06:13 org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
2 janv. 2014 23:06:13 org.apache.catalina.core.AprLifecycleListener initializeSSL
INFO: OpenSSL successfully initialized (OpenSSL 1.0.1e 11 Feb 2013)
2 janv. 2014 23:06:13 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-apr-8080"]
2 janv. 2014 23:06:13 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-apr-8009"]
2 janv. 2014 23:06:13 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 930 ms
2 janv. 2014 23:06:13 org.apache.catalina.core.StandardService startInternal
INFO: Démarrage du service Catalina
2 janv. 2014 23:06:13 org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
2 janv. 2014 23:06:13 org.apache.catalina.startup.HostConfig deployDirectory
INFO: Déploiement du répertoire C:\Apps\Tomcat\7.0.47_x64\webapps\docs de l'application web
2 janv. 2014 23:06:14 org.apache.tomcat.websocket.server.WsSci onStartup
INFO: JSR 356 WebSocket (Java WebSocket 1.0) support is not available when running on Java 6. To suppress this message, run Tomcat on Java 7,
remove the WebSocket JARs from $CATALINA_HOME/lib or add the WebSocketJARs to the tomcat.util.scan.DefaultJarScanner.jarsToSkip property in
$CATALINA_BASE/conf/catalina.properties. Note that the deprecated Tomcat 7 WebSocket API will be available.
2 janv. 2014 23:06:14 org.apache.catalina.startup.HostConfig deployDirectory
INFO: Déploiement du répertoire C:\Apps\Tomcat\7.0.47_x64\webapps\examples de l'application web
2 janv. 2014 23:06:14 org.apache.catalina.startup.HostConfig deployDirectory
INFO: Déploiement du répertoire C:\Apps\Tomcat\7.0.47_x64\webapps\host-manager de l'application web
2 janv. 2014 23:06:14 org.apache.catalina.startup.HostConfig deployDirectory
INFO: Déploiement du répertoire C:\Apps\Tomcat\7.0.47_x64\webapps\manager de l'application web
2 janv. 2014 23:06:14 org.apache.catalina.startup.HostConfig deployDirectory
INFO: Déploiement du répertoire C:\Apps\Tomcat\7.0.47_x64\webapps\ROOT de l'application web
2 janv. 2014 23:06:15 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-apr-8080"]
2 janv. 2014 23:06:15 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-apr-8009"]
2 janv. 2014 23:06:15 org.apache.catalina.startup.Catalina start
INFO: Server startup in 1094 ms


Stop-icon.png Arrêt

L'arrêt du serveur est aussi simple que le lancement, en exécutant le script shutdown.bat. Ce script sera étudié dans le chapitre suivant.

c:\Apps\Tomcat\7.0.47_x64\bin>shutdown.bat
Using CATALINA_BASE:   "c:\Apps\Tomcat\7.0.47_x64"
Using CATALINA_HOME:   "c:\Apps\Tomcat\7.0.47_x64"
Using CATALINA_TMPDIR: "c:\Apps\Tomcat\7.0.47_x64\temp"
Using JRE_HOME:        "C:\Apps\Java\jdk1.6.0_33_x64"
Using CLASSPATH:       "c:\Apps\Tomcat\7.0.47_x64\bin\bootstrap.jar;c:\Apps\Tomcat\7.0.47_x64\bin\tomcat-juli.jar"
c:\Apps\Tomcat\7.0.47_x64\bin>

Des informations d'arrêt du serveur apparaîssent dans la fenêtre ouverte suite au démarrage, puis elle se ferme.


Icon-Configuration-Settings.png Variables d'environnements

Les scripts de Tomcat sont particulièrement bien organisés et offrent de grandes possibilités de configurations. Cependant il est primordiale de les étudier afin de bien comprendre les fonctionnement mis en place. Deux variables sont régulièrement utilisées CATAINA_HOME et CATALINA_BASE, dont un exemple d'utilisation est expliqué sur l'installation de multiples instances.

Start-icon.png Script de démarrage

Le contenu du script startup.bat, les seules différences entre la version 6 et 7 se situe dans les commentaires, est le suivant:

@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 Start script for the CATALINA Server
rem
rem $Id: startup.bat 895392 2010-01-03 14:02:31Z kkolinko $
rem ---------------------------------------------------------------------------

rem Guess CATALINA_HOME if not defined
set "CURRENT_DIR=%cd%"
if not "%CATALINA_HOME%" == "" goto gotHome
set "CATALINA_HOME=%CURRENT_DIR%"
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
cd ..
set "CATALINA_HOME=%cd%"
cd "%CURRENT_DIR%"
:gotHome
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
echo The CATALINA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome

set "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat"

rem Check that target executable exists
if exist "%EXECUTABLE%" goto okExec
echo Cannot find "%EXECUTABLE%"
echo This file is needed to run this program
goto end
:okExec

rem Get remaining unshifted command line arguments and save them in the
set CMD_LINE_ARGS=
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setArgs
:doneSetArgs

call "%EXECUTABLE%" start %CMD_LINE_ARGS%

:end

Après le contrôle de la présence du fichier \bin\catalina.bat, celui-ci est exécuté avec l'argument start et l'hypothétique premier argument de la ligne de commande.

Start-icon.png Script d'arrêt

Le contenu du script shutdown.bat, les seules différences entre la version 6 et 7 se situe dans les commentaires, est le suivant:

@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 Stop script for the CATALINA Server
rem
rem $Id: shutdown.bat 908749 2010-02-10 23:26:42Z markt $
rem ---------------------------------------------------------------------------

rem Guess CATALINA_HOME if not defined
set "CURRENT_DIR=%cd%"
if not "%CATALINA_HOME%" == "" goto gotHome
set "CATALINA_HOME=%CURRENT_DIR%"
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
cd ..
set "CATALINA_HOME=%cd%"
cd "%CURRENT_DIR%"
:gotHome
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
echo The CATALINA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome

set "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat"

rem Check that target executable exists
if exist "%EXECUTABLE%" goto okExec
echo Cannot find "%EXECUTABLE%"
echo This file is needed to run this program
goto end
:okExec

rem Get remaining unshifted command line arguments and save them in the
set CMD_LINE_ARGS=
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setArgs
:doneSetArgs

call "%EXECUTABLE%" stop %CMD_LINE_ARGS%

:end

Comme dans le cadre du démarrage, après le contrôle de la présence du fichier \bin\catalina.bat, celui-ci est exécuté avec l'hypothétique premier argument de la ligne de commande.

Process-Icon.png Script principal

Les deux fichiers appelent donc le script principal catalina.bat. Son contenu varie en fonction des versions et serait un peu trop conséquent dans le cadre de cet article. Seules les commandes intéressantes vont être étudiées.

Dans ce bloc suivant, la présence du fichier bin\setenv.bat est contrôlé au niveau de CATALINA_HOME ou CATALINA_BASE. Si celui-ci existe, il est alors exécuté.

rem Get standard environment variables
if not exist "%CATALINA_BASE%\bin\setenv.bat" goto checkSetenvHome
call "%CATALINA_BASE%\bin\setenv.bat"
goto setenvDone
:checkSetenvHome
if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat"
:setenvDone

En fin de script, les lignes suivantes sont présentes:

if not "%JPDA%" == "" goto doJpda
if not "%SECURITY_POLICY_FILE%" == "" goto doSecurity
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" 
-Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end
:doSecurity
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager 
-Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end
:doJpda
if not "%SECURITY_POLICY_FILE%" == "" goto doSecurityJpda
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %JPDA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" 
-Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end
:doSecurityJpda
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %JPDA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager 
-Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end

Donc de nombreuses variables sont utilisées. Toutes sont enrichies au fur et à mesure de l'exécution. Par conséquent, il est envisageable de mettre une configuration particulière en affectant une valeur à partir du fichier setenv.bat. Les variables modifiables sont documentés dans l'en tête du script et sont pour rappel:

  • CATALINA_HOME
  • CATALINA_BASE
  • CATALINA_OPTS
  • CATALINA_TMPDIR
  • JAVA_HOME
  • JRE_HOME
  • JAVA_OPTS
  • JAVA_ENDORSED_DIRS
  • JPDA_TRANSPORT
  • JPDA_ADDRESS
  • JPDA_SUSPEND
  • JPDA_OPTS
  • LOGGING_CONFIG
  • LOGGING_MANAGER
  • TITLE

Pour beaucoup, c'est un peu la cerise sur le gâteau, mais certaines sont particulièrement intéressantes.

Examples-icon.png Java format icon.png Configuration JRE / JDK

Cet exemple va permettre de configurer un environnement JAVA spécifique pour l'exécution d'une instance de Tomcat.

Le principe d'installation des version de Tomcat peut également s'appliquer au version des JRE / JDKs. Si la variable JAVA_HOME n'est pas renseignée au niveau de la machine, l'exécution du script de démarrage va produire l'erreur suivante:

c:\Apps\Tomcat\6.0.37_x64\bin>startup.bat
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

Le message d'erreur est suffisament précis pour décrire l'anomalie. Il faut spécifier soit la variable JAVA_HOME, soit JRE_HOME. L'utilisation du script setenv.bat va alors permettre de spécifier une valeur, sans affecter l'ensemble de la machine. Il suffit de le créer dans le même répertoire que catalina.bat, dans le cadre de cet article car il est possible de jouer avec les variable CATALINA_HOME et CATALINA_BASE, avec le contenu suivant:

set JAVA_HOME=C:\Apps\Java\jdk1.6.0_33_x64

Aussi simplement, la variable JAVA_HOME va être configurée avec la valeur C:\Apps\Java\jdk1.6.0_33_x64 correspondant au répertoire de la JDK à utiliser. Et la portée de celle-ci se limite à l'exécution du script. Il n'y a donc aucun impact sur le reste des applications, sur la machine ...

Et l'exécution du démarrage se déroule correctement.

c:\Apps\Tomcat\6.0.37_x64\bin>startup.bat
Using CATALINA_BASE:   "C:\Apps\Tomcat\6.0.37_x64"
Using CATALINA_HOME:   "C:\Apps\Tomcat\6.0.37_x64"
Using CATALINA_TMPDIR: "C:\Apps\Tomcat\6.0.37_x64\temp"
Using JRE_HOME:        "C:/Apps/Java/jdk1.6.0_33_x64"
Using CLASSPATH:       "C:\Apps\Tomcat\6.0.37_x64\bin\bootstrap.jar"

Warning-icon.png, la console indique l'utilisation de JRE_HOME alors que la variable mise ne place est JAVA_HOME. Cette "confusion" provient de quelques instructions dans le script setclasspath.bat exécuté durant le déroulement de catalina.bat:

Version 6.0.37

@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 Set CLASSPATH and Java options
rem
rem $Id: setclasspath.bat 908749 2010-02-10 23:26:42Z markt $
rem ---------------------------------------------------------------------------

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 At least one of these environment variable is needed to run this program
goto exit

:gotJreHome
if not exist "%JRE_HOME%\bin\java.exe" goto noJavaHome
if not exist "%JRE_HOME%\bin\javaw.exe" goto noJavaHome
if not ""%1"" == ""debug"" goto okJavaHome
echo JAVA_HOME should point to a JDK in order to run in debug mode.
goto exit

: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\jdb.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 exit
:okJavaHome

if not "%BASEDIR%" == "" goto gotBasedir
echo The BASEDIR environment variable is not defined
echo This environment variable is needed to run this program
goto exit
:gotBasedir
if exist "%BASEDIR%\bin\setclasspath.bat" goto okBasedir
echo The BASEDIR environment variable is not defined correctly
echo This environment variable is needed to run this program
goto exit
:okBasedir

rem Don't override the endorsed dir if the user has set it previously
if not "%JAVA_ENDORSED_DIRS%" == "" goto gotEndorseddir
rem Set the default -Djava.endorsed.dirs argument
set "JAVA_ENDORSED_DIRS=%BASEDIR%\endorsed"
:gotEndorseddir

rem Set standard command for invoking Java.
rem Note that NT requires a window name argument when using start.
rem Also note the quoting as JAVA_HOME may contain spaces.
set _RUNJAVA="%JRE_HOME%\bin\java"
set _RUNJDB="%JAVA_HOME%\bin\jdb"

goto end

:exit
exit /b 1

:end
exit /b 0

Si la valeur de JAVA_HOME est disponible, le script se dirige vers la section gotJdkHome où un ensemble de contrôles est réalisé. Si ceux-ci sont validés, la valeur de JRE_HOME est mise à jour, si celle-ci n'est pas déjà renseignée, avec la valeur de JAVA_HOME.

Version 7.0.47

@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 Set JAVA_HOME or JRE_HOME if not already set, ensure any provided settings
rem are valid and consistent with the selected start-up options and set up the
rem endorsed directory.
rem
rem $Id: setclasspath.bat 1202062 2011-11-15 06:50:02Z mturk $
rem ---------------------------------------------------------------------------

rem Make sure prerequisite environment variables are set

rem In debug mode we need a real JDK (JAVA_HOME)
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
if not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHome
set "JRE_HOME=%JAVA_HOME%"
goto okJava

:noJavaHome
echo The JAVA_HOME environment variable is not defined correctly.
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
set "JRE_HOME=%JAVA_HOME%"

:gotJreHome
rem Check if we have a usable JRE
if not exist "%JRE_HOME%\bin\java.exe" goto noJreHome
if not exist "%JRE_HOME%\bin\javaw.exe" goto noJreHome
goto okJava

:noJreHome
rem Needed at least a JRE
echo The JRE_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto exit

:okJava
rem Don't override the endorsed dir if the user has set it previously
if not "%JAVA_ENDORSED_DIRS%" == "" goto gotEndorseddir
rem Set the default -Djava.endorsed.dirs argument
set "JAVA_ENDORSED_DIRS=%CATALINA_HOME%\endorsed"
:gotEndorseddir

rem Set standard command for invoking Java.
rem Note that NT requires a window name argument when using start.
rem Also note the quoting as JAVA_HOME may contain spaces.
set _RUNJAVA="%JRE_HOME%\bin\java"
set _RUNJDB="%JAVA_HOME%\bin\jdb"

goto end

:exit
exit /b 1

:end
exit /b 0

Dans ce cas, les affectations sont encore plus radicale. Par défaut si JRE_HOME est renseignée c'est celle-ci qui est prise par défaut et ne contrôle même plus JAVA_HOME. Dans le cas contraire, la valeur de JAVA_HOME lui est affectée.


Puis dans le script catalinat.bat, c'est la valeur de JRE_HOME qui est présentée, sauf si il est exécuté avec l'argument debug dans la ligne de commande.

echo Using CATALINA_BASE:   "%CATALINA_BASE%"
echo Using CATALINA_HOME:   "%CATALINA_HOME%"
echo Using CATALINA_TMPDIR: "%CATALINA_TMPDIR%"
if ""%1"" == ""debug"" goto use_jdk
echo Using JRE_HOME:        "%JRE_HOME%"
goto java_dir_displayed
:use_jdk
echo Using JAVA_HOME:       "%JAVA_HOME%"
:java_dir_displayed
echo Using CLASSPATH:       "%CLASSPATH%"