Tomcat : Running multiple tomcat instances on Windows

This page last changed on Feb 02, 2009 by Kees de Kooter

Applies to Tomcat 6.0. The following procedure was tested on a Windows Server 2003 R2 box, but should work on all Windows NT based OS-es.

Copy instance specific files

I created a subdirectory instance under %CATALINA_HOME%. From a freshly installed Tomcat (using the Windows installer) I copied conf, logs, temp, webapps and work to a subdir named template.

Modify ports in server.xml

The port numbers for Service, Connector HTTP and Connector AJP have to be unique. I solved this by incrementing the second digit of every portnumber, i.e. 8180, 8280 etc.

Create the windows service

A windows service can be created by running tomcat6 with a myriad of command line options which are documented on the tomcat site. I put the essential ones in a script.

The script

Note that the tomcat6 command should all be on one line!

create-instance.bat

@echo off
rem 
rem Batch file for creating Windows services for tomcat instances.
rem Assumption: environment variable CATALINA_HOME is set
rem
rem Author: Kees de Kooter
rem Date: 29-12-2008
rem
rem Parameter: instance name (only alphanumeric characters: [A-Za-z0-9]*)
rem 
rem TODO: copy instance files first
rem copy %CATALINA_HOME%\instances\template %CATALINA_HOME%\instances\%1
rem TODO: make modifications to server.xml

cd %CATALINA_HOME%\bin

set CATALINA_BASE=%CATALINA_HOME%\instances\%1

rem Delete service if it already exists
tomcat6 //DS//%1

tomcat6 //IS//%1 \
--DisplayName="Tomcat 6 Instance %1" \
--Description="Tomcat 6 Instance %1" \
--Install="%CATALINA_HOME%\bin\tomcat6.exe" \
--Classpath="%CATALINA_HOME%\bin\bootstrap.jar" \
--Jvm=auto \
--Startup=auto \
--StartMode=jvm \
--StartPath="%CATALINA_HOME%" \
--StopMode=jvm \
--StartClass=org.apache.catalina.startup.Bootstrap \
--StartParams=start \
--StopClass=org.apache.catalina.startup.Bootstrap \
--StopParams=stop \
--StopPath="%CATALINA_HOME%" \
--Startup=auto \
--LogPath="%CATALINA_BASE%\logs" \
--StdOutput=auto \
--StdError=auto \
--JvmOptions="-Dcatalina.home=%CATALINA_HOME%;-Dcatalina.base=%CATALINA_BASE%;-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed"

rem TODO: add memory settings

rem Copy service applet tomcat6w.exe to instance name
copy tomcat6w.exe %1w.exe /Y

References

http://tomcat.apache.org/tomcat-6.0-doc/windows-service-howto.html