Logo vawacon Jochen van Waasen
Senior Developer Java Technology
Contents
Start
Services
Resume
Technology
Imprint
Relocate directory
Abstract
Prerequisites
Install Tomcat 4 (NT service)
Install NT service manually
Install NT service using ANT
Uninstall NT service
 
Download:
tomcatService.xml
tS.properties
Instructions: HowTo_PDF
 
2003-09-03 15:52
How to integrate Apache 2 with Tomcat 4 on Windows?
Abstract:
This text covers the installation of Tomcat 4 as NT service and the creation of Tomcat NT services. The creation of NT services can be used if during the installation of Tomcat 4 the installation option NT service was not checked or a relocated web application directory is used. Also Multiple Tomcat instances on the same machine can be run as NT service.

These instructions have been tested on Windows 2000 with Tomcat 4.1.24.
Prerequisites:
Properly installed J2SE SDK with JAVA_HOME set in your environment.
Installing Tomcat 4 (NT service) :
1. Download the Windows binaries: tomcat-4.1.24.exe
2. Install Tomcat 4 by double-clicking on the downloaded file and following the prompts.
2a. As Installation Option choose Custom and check the NT Service (NT/2K/XP only) check-box:
Screenshot Tomcat installation

Tomcat is installed as NT Service !

With this option a NT Service is created in the Windows registry and the service is started after the installation is completed. The started service uses the instance and the web application directory in the Tomcat installation directory specified during installation.

To create and start the service the file tomcat.exe is extracted to the bin directory of the Tomcat installation directory. This also can be used to create a NT service manually and is only extracted if the NT Service option was selected during the installation.

2b. Follow the next prompts.
3. Set CATALINA_HOME in your environment to point to the Tomcat 4.1 installation directory.
Install NT service manually :
  If Tomcat was not installed as NT service a new NT service has to be created manually . Tomcat itself provides a tool to create manually a Tomcat NT service for an existing installation.
 

Using the Windows installer tomcat.exe is only extracted to the bin directory of the Tomcat installation directory if you have chosen the NT Service option during installation. If you do not find the tomcat.exe file in the bin directory of the Tomcat installation directory no service was installed during installation.

You can uninstall Tomcat and install it again with the NT Service option checked to get the file. If you do not want to reinstall Tomcat you can download the tomcat-4.1.24.zip distribution file and extract the tomcat.exe file and copy it to the bin directory of your Tomcat installation directory.

This tool can be found in the bin directory of the Tomcat installation directory.
tomcat.exe

  Usage oftomcat.exe
\ tomcat -?


To install a service:
-install service_name jvm_library (jvm_option)*
-start start_class [-method start_method] [-params (start_parameter)+]
[-stop start_class [-method stop_method] [-params (stop_parameter)+]]
[-out out_log_file] [-err err_log_file]
[-current current_dir]
[-path extra_path]

To uninstall a service:
-uninstall service_name
[...]
 

There are a lot of options that make the command tomcat.exe very inconvenient to handle.

-install Service_name Path_to_Server_JVM

-Dcatalina.home
Path to the installation directory of Tomcat. Here are all the
classes needed to run the server.

-Dcatalina.base Path to the web application directory. This is the directory of
the deployed web application.

-Djava.endorsed.dirs Path to endorsed resources: xercesImpl.jar, xmlParserAPI.jar
These come with the Tomcat installation.

-Djava.class.path
Path to the Bootstrap.jar needed for starting the service.

-start
Start class, method and parameters to start the service.

-stop
Stop class, method and parameters to stop the service.

-out
Path to output log file.

-err
Path to error log file.


This is a sample to create a Tomcat NT service.


C:\Tomcat4\bin tomcat -install Tomcat_Instance_2
D:\DEV\j2sdk14103\jre\bin\server\jvm.dl
-Dcatalina.home=D:\server\ApacheGroup\Tomcat4
-Dcatalina.base=D:\server\tomcat-instances\instance2
-Djava.endorsed.dirs=D:\server\ApacheGroup\Tomcat4\common\endorsed
-Djava.class.path=D:\server\ApacheGroup\Tomcat4\bin\bootstrap.jar
-Xrs -Xms64m -Xss1024k -Xmx256m
-start org.apache.catalina.startup.BootstrapService -method main -params start
-stop org.apache.catalina.startup.BootstrapService -method main -params stop
-out D:\server\tomcat-instances\instance1\logs\Tomcat_Instance_2_out.log
-err D:\server\to mcat-instances\instance1\logs\Tomcat_Instance_2_err.log


This is all in ONE line so that the tomcat command can parse all options.

As you can see, this is very hard to handle even if you want to create more than one service.

Install NT service using ANT :
  The inconvenient task to manually install a NT service can easily be done using ANT.
  The ANT buildfile tomcatService.xml in combination with the tS.properties file takes care of installing a NT service.
1. You need a properly installed ANT distribution!
2. The tomcatService.xml expects the follwing:

JAVA_HOME set in environment pointing to the J2SE installation directory.
CATALINA_HOME set in environment pointing to the Tomcat 4 installation directory.
3. Modify tS.properties :

# Path to the Tomcat instance / application
# Use \ (backslash) as this path is used within the Windows Registry
CATALINA_BASE =D:\\server\\tomcat-instances\\instance3

# Name of service used by Windows
SERVICE_NAME =Tomcat_Instance_A2

# Description of the service used by Windows
SERVICE_DESCRIPTION=Tomcat Instance Service

# VM attributes
# See J2SE tooldocs!
XMS=-Xms64M
XSS=-Xss1024K
XMX=-Xmx256M


Modify CATALINA_BASE to point to your web application directory. If you do not use a distributed web application directory or multiple instances of Tomcat point it to the Tomcat installation directory.

Use a SERVICE_NAME so you can easily identify the Tomcat instance among the Windows services.
4. Execute the tomcatService.xml with ANT!

D:\ ant -buildfile tomcatService.xml

Buildfile: tomcatService.xml

main:
[echo] Install Tomcat as Service (Tomcat_Instance_A2) on Windows 2000!
[echo] Created D:\server\ApacheGroup\Tomcat4\bin\Tomcat_Instance_A2.exe !
[exec] The service was successfully installed.
[echo] Creating description file for Windows registry.
[echo] Updating registry with description.
[echo] Deleting description file for Windows registry.
[delete] Deleting: D:\service.reg

BUILD SUCCESSFUL
Total time: 1 second


The NT service is now created but not started.
Go to Start > Settings > Control Panel > Administrative Tools > Services .
Select your named service and start it.
The service is automatically started after rebooting the system.
Uninstall NT service :
  Tomcat itself provides a tool to uninstall a Tomcat NT service.

It is the same tool to install a NT service. This tool can be found in the bin directory of the Tomcat installation directory.
tomcat.exe

\ tomcat -?
[...]
To uninstall a service:
-uninstall service_name
[...]
1. Stop the NT service.
Go to Start > Settings > Control Panel > Administrative Tools > Services .
Select your named service and stop it.
2. Uninstall the NT service.
Go to the bin directory in the Tomcat installation directory.
tomcat -uninstall Tomcat_Instance_A2
  webmaster@vawacon.ch © 2001-2005 van waasen system consulting