- Apache Tomcat 9
- Windows service HOW-TO
- Table of Contents
- Tomcat service application
- Tomcat monitor application
- Command line arguments
- Command line parameters
- Installing services
- Apache Tomcat 9
- Windows Service How-To
- Table of Contents
- Tomcat service application
- Tomcat monitor application
- Command line arguments
- Command line parameters
- Installing services
Apache Tomcat 9
Windows service HOW-TO
Table of Contents
Tomcat service application
Tomcat9 is a service application for running Tomcat 9 as a Windows service.
Tomcat monitor application
Tomcat9w is a GUI application for monitoring and configuring Tomcat services.
The available command line options are:
//ES// | Edit service configuration | This is the default operation. It is called if the no option is provided but the executable is renamed to servicenameW.exe |
//MS// | Monitor service | Put the icon in the system tray |
Command line arguments
Each command line directive is in the form of //XX//ServiceName
The available command line options are:
//TS// | Run the service as console application | This is the default operation. It is called if the no option is provided. The ServiceName is the name of the executable without exe suffix, meaning Tomcat9 |
//RS// | Run the service | Called only from ServiceManager |
//SS// | Stop the service | |
//US// | Update service parameters | |
//IS// | Install service | |
//DS// | Delete service | Stops the service if running |
Command line parameters
Each command line parameter is prefixed with —. If the command line parameter is prefixed with ++ then it’s value will be appended to the existing option. If the environment variable with the same name as command line parameter but prefixed with PR_ exists it will take precedence. For example:
is equivalent to providing
as command line parameter.
ParameterName | Default | Description |
---|---|---|
—Description | Service name description (maximum 1024 characters) | |
—DisplayName | ServiceName | Service display name |
—Install | procrun.exe //RS//ServiceName | Install image |
—Startup | manual | Service startup mode can be either auto or manual |
—DependsOn | List of services that this service depend on. Dependent services are separated using either # or ; characters | |
—Environment | List of environment variables that will be provided to the service in the form key=value. They are separated using either # or ; characters. If you need to use either the # or ; character within a value then the entire value must be enclosed inside single quotes. | |
—User | User account used for running executable. It is used only for StartMode java or exe and enables running applications as service under account without LogonAsService privilege. | |
—Password | Password for user account set by —User parameter | |
—JavaHome | JAVA_HOME | Set a different JAVA_HOME than defined by JAVA_HOME environment variable |
—Jvm | auto | Use either auto (i.e. find the JVM from the Windows registry) or specify the full path to the jvm.dll. You can use the environment variable expansion here. |
—JvmOptions | -Xrs | List of options in the form of -D or -X that will be passed to the JVM. The options are separated using either # or ; characters. If you need to embed either # or ; characters, put them inside single quotes. (Not used in exe mode.) |
—JvmOptions9 | List of options in the form of -D or -X that will be passed to the JVM when running on Java 9 or later. The options are separated using either # or ; characters. If you need to embed either # or ; characters, put them inside single quotes. (Not used in exe mode.) | |
—Classpath | Set the Java classpath. (Not used in exe mode.) | |
—JvmMs | Initial memory pool size in MB. (Not used in exe mode.) | |
—JvmMx | Maximum memory pool size in MB. (Not used in exe mode.) | |
—JvmSs | Thread stack size in KB. (Not used in exe mode.) | |
—StartMode | One of jvm, Java or exe. The modes are:
| |
—StartImage | Executable that will be run. Only applies to exe mode. | |
—StartPath | Working path for the start image executable. | |
—StartClass | Main | Class that contains the startup method. Applies to the jvm and Java modes. (Not used in exe mode.) |
—StartMethod | main | Method name if differs then main |
—StartParams | List of parameters that will be passed to either StartImage or StartClass. Parameters are separated using either # or ; character. | |
—StopMode | One of jvm, Java or exe. See —StartMode for further details. | |
—StopImage | Executable that will be run on Stop service signal. Only applies to exe mode. | |
—StopPath | Working path for the stop image executable. Does not apply to jvm mode. | |
—StopClass | Main | Class that will be used on Stop service signal. Applies to the jvm and Java modes. |
—StopMethod | main | Method name if differs then main |
—StopParams | List of parameters that will be passed to either StopImage or StopClass. Parameters are separated using either # or ; character. | |
—StopTimeout | No Timeout | Defines the timeout in seconds that procrun waits for service to exit gracefully. |
—LogPath | %SystemRoot%\System32\LogFiles\Apache | Defines the path for logging. Creates the directory if necessary. |
—LogPrefix | commons-daemon | Defines the service log filename prefix. The log file is created in the LogPath directory with .YEAR-MONTH-DAY.log suffix |
—LogLevel | Info | Defines the logging level and can be either Error, Info, Warn or Debug. (Case insensitive). |
—StdOutput | Redirected stdout filename. If named auto then file is created inside LogPath with the name service-stdout.YEAR-MONTH-DAY.log. | |
—StdError | Redirected stderr filename. If named auto then file is created inside LogPath with the name service-stderr.YEAR-MONTH-DAY.log. | |
—PidFile | Defines the file name for storing the running process id. Actual file is created in the LogPath directory |
Installing services
The safest way to manually install the service is to use the provided service.bat script. Administrator privileges are required to run this script. If necessary, you can use the /user switch to specify a user to use for the installation of the service.
NOTE: On Windows Vista or any later operating system with User Account Control (UAC) enabled you will be asked for additional privileges when ‘Tomcat9.exe’ is launched by the script.
If you want to pass additional options to service installer as PR_* environment variables, you have to either configure them globally in OS, or launch the program that sets them with elevated privileges (e.g. right-click on cmd.exe and select «Run as administrator»; on Windows 8 (or later) or Windows Server 2012 (or later), you can open an elevated command prompt for the current directory from the Explorer by clicking on the «File» menu bar). See issue 56143 for details.
There is a 2nd optional parameter that lets you specify the name of the service, as displayed in Windows services.
If using tomcat9.exe, you need to use the //IS// parameter.
Apache Tomcat 9
Windows Service How-To
Table of Contents
Tomcat service application
Tomcat9 is a service application for running Tomcat 9 as a Windows service.
Tomcat monitor application
Tomcat9w is a GUI application for monitoring and configuring Tomcat services.
The available command line options are:
//ES// | Edit service configuration | This is the default operation. It is called if the no option is provided but the executable is renamed to servicenameW.exe |
//MS// | Monitor service | Put the icon in the system tray |
Command line arguments
Each command line directive is in the form of //XX//ServiceName
The available command line options are:
//TS// | Run the service as console application | This is the default operation. It is called if the no option is provided. The ServiceName is the name of the executable without exe suffix, meaning Tomcat9 |
//RS// | Run the service | Called only from ServiceManager |
//SS// | Stop the service | |
//US// | Update service parameters | |
//IS// | Install service | |
//DS// | Delete service | Stops the service if running |
Command line parameters
Each command line parameter is prefixed with —. If the command line parameter is prefixed with ++ then it’s value will be appended to the existing option. If the environment variable with the same name as command line parameter but prefixed with PR_ exists it will take precedence. For example:
is equivalent to providing
as command line parameter.
ParameterName | Default | Description |
---|---|---|
—Description | Service name description (maximum 1024 characters) | |
—DisplayName | ServiceName | Service display name |
—Install | procrun.exe //RS//ServiceName | Install image |
—Startup | manual | Service startup mode can be either auto or manual |
—DependsOn | List of services that this service depend on. Dependent services are separated using either # or ; characters | |
—Environment | List of environment variables that will be provided to the service in the form key=value. They are separated using either # or ; characters. If you need to use either the # or ; character within a value then the entire value must be enclosed inside single quotes. | |
—User | User account used for running executable. It is used only for StartMode java or exe and enables running applications as service under account without LogonAsService privilege. | |
—Password | Password for user account set by —User parameter | |
—JavaHome | JAVA_HOME | Set a different JAVA_HOME than defined by JAVA_HOME environment variable |
—Jvm | auto | Use either auto (i.e. find the JVM from the Windows registry) or specify the full path to the jvm.dll. You can use the environment variable expansion here. |
—JvmOptions | -Xrs | List of options in the form of -D or -X that will be passed to the JVM. The options are separated using either # or ; characters. If you need to embed either # or ; characters, put them inside single quotes. (Not used in exe mode.) |
—JvmOptions9 | List of options in the form of -D or -X that will be passed to the JVM when running on Java 9 or later. The options are separated using either # or ; characters. If you need to embed either # or ; characters, put them inside single quotes. (Not used in exe mode.) | |
—Classpath | Set the Java classpath. (Not used in exe mode.) | |
—JvmMs | Initial memory pool size in MB. (Not used in exe mode.) | |
—JvmMx | Maximum memory pool size in MB. (Not used in exe mode.) | |
—JvmSs | Thread stack size in KB. (Not used in exe mode.) | |
—StartMode | One of jvm, Java or exe. The modes are:
| |
—StartImage | Executable that will be run. Only applies to exe mode. | |
—StartPath | Working path for the start image executable. | |
—StartClass | Main | Class that contains the startup method. Applies to the jvm and Java modes. (Not used in exe mode.) |
—StartMethod | main | Method name if differs then main |
—StartParams | List of parameters that will be passed to either StartImage or StartClass. Parameters are separated using either # or ; character. | |
—StopMode | One of jvm, Java or exe. See —StartMode for further details. | |
—StopImage | Executable that will be run on Stop service signal. Only applies to exe mode. | |
—StopPath | Working path for the stop image executable. Does not apply to jvm mode. | |
—StopClass | Main | Class that will be used on Stop service signal. Applies to the jvm and Java modes. |
—StopMethod | main | Method name if differs then main |
—StopParams | List of parameters that will be passed to either StopImage or StopClass. Parameters are separated using either # or ; character. | |
—StopTimeout | No Timeout | Defines the timeout in seconds that procrun waits for service to exit gracefully. |
—LogPath | %SystemRoot%\System32\LogFiles\Apache | Defines the path for logging. Creates the directory if necessary. |
—LogPrefix | commons-daemon | Defines the service log filename prefix. The log file is created in the LogPath directory with .YEAR-MONTH-DAY.log suffix |
—LogLevel | Info | Defines the logging level and can be either Error, Info, Warn or Debug. (Case insensitive). |
—StdOutput | Redirected stdout filename. If named auto then file is created inside LogPath with the name service-stdout.YEAR-MONTH-DAY.log. | |
—StdError | Redirected stderr filename. If named auto then file is created inside LogPath with the name service-stderr.YEAR-MONTH-DAY.log. | |
—PidFile | Defines the file name for storing the running process id. Actual file is created in the LogPath directory |
Installing services
The safest way to manually install the service is to use the provided service.bat script. Administrator privileges are required to run this script. If necessary, you can use the /user switch to specify a user to use for the installation of the service.
NOTE: If User Account Control (UAC) is enabled you will be asked for additional privileges when ‘Tomcat9.exe’ is launched by the script.
If you want to pass additional options to service installer as PR_* environment variables, you have to either configure them globally in OS, or launch the program that sets them with elevated privileges (e.g. right-click on cmd.exe and select «Run as administrator»; on Windows 8 (or later) or Windows Server 2012 (or later), you can open an elevated command prompt for the current directory from the Explorer by clicking on the «File» menu bar). See issue 56143 for details.
There is a 2nd optional parameter that lets you specify the name of the service, as displayed in Windows services.
When installing the service with a non-default name, tomcat9.exe and tomcat9w.exe may be renamed to match the chosen service name. To do this, use the —rename option.
If using tomcat9.exe, you need to use the //IS// parameter.