Following instructions were based on Tomcat 6 and are now updated for Tomcat 9. The specifics are compatible with all Tomcat from version 6.
Assuming you already have extracted Tomcat, navigate to
bin folder of your Tomcat installation. The folder should contain three files:
tomcat9w.exe. If you are using other Tomcat version than these files might be
tomcatXw.exe where ‘X’ is Tomcat major version number.
If these files are not there, then you have to manually add them, otherwise skip to the next step.
1.1 Adding service management files
First, figure out which version of Tomcat you have and figure out architecture (x86 or x64). Next, go to one of Tomcat download pages and download Windows Service Installer.
For newer versions of Tomcat find appropriate download page on official Tomcat website.
Extract downloaded archive and navigate to
bin folder and copy
tomcatXw.exe to your Tomcat installation.
1.2 Install Windows Service
Firstly, stop Tomcat Server if is running. Then open
Powershell window (with Administrator privileges) and navigate to Tomcat’s
bin directory where you should have all three files. Execute following command:
Command output for Tomcat 9:
Installing the service 'Tomcat9' ... Using CATALINA_HOME: "C:\apache-tomcat-9.0.19" Using CATALINA_BASE: "C:\apache-tomcat-9.0.19" Using JAVA_HOME: "C:\Program Files\Java\jdk1.8.0_201" Using JRE_HOME: "C:\Program Files\Java\jdk1.8.0_201\jre" Using JVM: "C:\Program Files\Java\jdk1.8.0_201\jre\bin\server\jvm.dll" The service 'Tomcat9' has been installed.
If command has executed successfully, a new service should be visible under Windows Services with name Apache Tomcat 9.0 Tomcat9.
1.3 Configure Windows Service
Following instruction are based on Tomcat official guide available at
Powershell run following command:
//ES//is the default operation. It is called if the no option is provided but the executable is renamed to servicenameW.exe
A new Tomcat Windows Service Configuration windows should be visible. Here you can configure service name, description, startup type, JVM settings, etc. At least what you want to do is to set startup type to Automatic and increase Maximum Memory Pool under Java tab.
For Java versions prior to Java 8, add a new line
-XX:MaxPermSize=256m under Java Options section. This will increase Java heap size. You sure want to modify value for your needs. This setting is very important as running Tomcat as service will override all other settings from default Tomcat except to this.
Now you can start Tomcat as a service. Run (Windows + R)
services.msc or access it from the Tak Manager (Services tab).
This way you can automatically start Tomcat Server on Windows start.
1.4 Remove Windows Service
Powershell window and navigate to Tomcat’s
bin directory. Run following commmand:
Output for Tomcat 9.x:
Removing the service 'Tomcat9' ... Using CATALINA_BASE: "C:\apache-tomcat-9.0.19" The service 'Tomcat9' has been removed