Register Tomcat to Window Service

Register Tomcat to Window Service

1. Software and Environment

  • Environment: JDK1.8
  • Application service: Tomcat9.0 (non-installation version)
  • Operating System: Windows 2012

2. Set Tomcat as a system service

win+R to open the run window, enter cmd to open the dos window, and use the cd command to switch the location to the bin file in the tomcat path.

cd C:\apache-tomcat-9.0.8\bin。输入service命令可以查看service.bat文件的使用说明,

C:\apache-tomcat-9.0.8\bin>service.bat

Usage: service.bat install/remove [service_name] [/user username]

C:\apache-tomcat-9.0.8\bin>

Enter service.bat install service_name to install the service. service_name is the name given to the service. You can name it yourself. The name I named here is TomcatService.

C:\apache-tomcat-9.0.8\bin>service install TomcatService
Installing the service 'TomcatService' ...
Using CATALINA_HOME:    "C:\apache-tomcat-9.0.8"
Using CATALINA_BASE:    "C:\apache-tomcat-9.0.8"
Using JAVA_HOME:        "C:\Program Files\Java\jdk1.8.0_171"
Using JRE_HOME:         "C:\Program Files\Java\jdk1.8.0_171\jre"
Using JVM:              "C:\Program Files\Java\jdk1.8.0_171\jre\bin\server\jvm.d
ll"
The service 'TomcatService' has been installed.

C:\apache-tomcat-9.0.8\bin>

3. Modify the startup method

win+R to open the run window, enter the control command to open the control panel, find the management tool, open the service, and you can see a newly registered service named Apache Tomcat 9.0 TomcatService. Right-click, select Properties, and change the startup type to Automatic.

4. Set up dependent services

Sometimes, we need to start the database service first, and then start the Tomcat service. That is to say, the database service is started automatically after booting. After the startup is completed, the Tomcat service should be automatically started. This is to set the Tomcat service and the database service dependency to be enabled.
Suppose there is a registered database service on the computer, the name is MySQLService, and now to set the dependency of TomcatService and MySQLService to open, use the sc config TomcatService depend= MySQLService command to execute (note that there must be a space between depend= and MySQLService ). After setting, you can view it in the properties of the service --> Dependencies.

5. Delete the registered service

Delete the registered service, similar to the install command, using remove. Open the dos window and enter service remove tomcat99 to delete the service.

C:\apache-tomcat-9.0.8\bin>service.bat remove tomcat99
Removing the service 'tomcat99' ...
Using CATALINA_BASE:    "C:\apache-tomcat-9.0.8"
The service 'tomcat99' has been removed

C:\apache-tomcat-9.0.8\bin>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325390239&siteId=291194637