Tomcat multiple instances simultaneously

Bruno Klein picture Bruno Klein · Apr 19, 2013 · Viewed 49.3k times · Source

I am trying to run multiple instances of Tomcat, but even after configuring different ports for listening and shutting down the second instance, it keeps trying to listen on 8080 (configured for 8081). I read that I have to set a different value for CATALINA_BASE. From all the articles there are online, none of them actually show in which file this variable can be set.

Where and how can I set CATALINA_BASE for my Tomcat instance in C:\apache-tomcat-7.0.39

Answer

Goran Vasic picture Goran Vasic · Feb 21, 2014

Let's say that you have only one Tomcat folder located in C:\apache-tomcat-7.0.39, and that you wish to run two instances from it.

Make sure that you have CATALINA_HOME system/user variable set, and pointing to C:\apache-tomcat-7.0.39

  1. Create a folder C:\instance1. Copy conf, webapps and temp folders from C:\apache-tomcat-7.0.39 and paste them to C:\instance1. You can delete contents from webapps and temp folders located under instance1, but don't touch conf contents.

  2. Now copy>paste C:\instance1 and rename it to instance2. That way, both instance1 and instance2 will have the same content.

  3. Go to C:\instance2\conf, edit server.xml and change the numbers of these ports (I marked those as XXXX):

    <Server port="XXXX" shutdown="SHUTDOWN">

    <Connector port="XXXX" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

    <Connector port="XXXX" protocol="AJP/1.3" redirectPort="8443" />

  4. Deploy whatever you want into instance1\webapps and instance2\webapps

  5. Create the following 4 batch files under C:\

instance1_startup.bat

@echo off

set CATALINA_BASE=C:\instance1

cd "%CATALINA_HOME%\bin"

set TITLE=My Tomcat Instance 01

call startup.bat %TITLE%

instance1_shutdown.bat

@echo off

set CATALINA_BASE=C:\instance1

cd "%CATALINA_HOME%\bin"

call shutdown.bat

instance2_startup.bat

@echo off

set CATALINA_BASE=C:\instance2

cd "%CATALINA_HOME%\bin"

set TITLE=My Tomcat Instance 02

call startup.bat %TITLE%

instance2_shutdown.bat

@echo off

set CATALINA_BASE=C:\instance2

cd "%CATALINA_HOME%\bin"

call shutdown.bat

  1. Run instance1_startup.bat and instance2_startup.bat, hopefully it should work.