{channel.title!channel.name} - 楚淮公司周东林

将TomCat安装为windows服务

TomCat官方网站下载的TOMCAT6windows64位版本是免安装版不方便管理,运行BIN目录下的Tomcat6w.exe报指定服务没安装错误。通过修改配置文件将TOMCAT加入WINDOWS服务。


1.配置service.bat文件

1.1找到TOMCAT主目录在二级bin目录下找到service.bat文件,鼠标右击选择编辑

文档会以txt方式打开文件在开头部分加入以下三行代码


SET JAVA_HOME=C:\Program Files\Java\jdk1.7.0_80
SET CATALINA_HOME=D:\apache-tomcat-6.0.48-windows-x64\tomcat6
SET PR_DISPLAYNAME=Tomcat6

第一行是设置JDK的目录,我用的是1.7版本这里要根据跟人实际情况修改;第二行设置TOMCAT的主目录也要根据个人情况修改成自己的目录;第三行设置服务名称,我这里设置的叫Tomcat6也可以设置成其它的(建议不要设置成其他名称)要和下面的修改一致尽量设置一眼可以认出来的服务名。

1.2继续找到

rem Set default Service name
set SERVICE_NAME=Tomcat6

修改为

rem Set default Service name
set SERVICE_NAME=Tomcat6

因为我上面设置SET PR_DISPLAYNAME=Tomcat6所以这一步不用修改

2.配置shutdown.bat和startup.bat文件

2.1TOMCAT主目录在二级bin目录下找到shutdown.bat文件,鼠标右击选择编辑

文档会以txt方式打开文件在开头部分加入以下两行代码

SET JAVA_HOME=C:\Program Files\Java\jdk1.7.0_80
SET CATALINA_HOME=D:\apache-tomcat-6.0.48-windows-x64\tomcat6

2.2TOMCAT主目录在二级bin目录下找到startup.bat文件,鼠标右击选择编辑

文档会以txt方式打开文件在开头部分加入以下两行代码

SET JAVA_HOME=C:\Program Files\Java\jdk1.7.0_80
SET CATALINA_HOME=D:\apache-tomcat-6.0.48-windows-x64\tomcat6

3.将Tomcat加入windows服务

3.1进入Tomcat的bin目录

运行Win+R打开运行对话框,输入cmd命令打开控制台输入

d:      //按回车键进入D盘

cd D:\apache-tomcat-6.0.48-windows-x64\tomcat6\bin           //按回车键进入Tomcat的bin目录

3.2安装Tomcat服务

service install Tomcat6      //按回车进行安装服务install Tomcat6必须跟前面设置的一致建议不要修改

如果提示以下错误

The tomcat6.exe was not found...
The CATALINA_HOME environment variable is not defined correctly.
This environment variable is needed to run this program

是因为你的Tomcat目录设置不对,Tomcat存放目录和设置目录不一致导致的

出现下面提示表示安装成功

D:\apache-tomcat-6.0.48-windows-x64\tomcat6\bin>service install Tomcat6

D:\apache-tomcat-6.0.48-windows-x64\tomcat6\bin>SET JAVA_HOME=C:\Program Files\J
ava\jdk1.7.0_80

D:\apache-tomcat-6.0.48-windows-x64\tomcat6\bin>SET CATALINA_HOME=D:\TomcatServe
rs\tomcat6

D:\apache-tomcat-6.0.48-windows-x64\tomcat6\bin>SET PR_DISPLAYNAME=Tomcat6
The tomcat6.exe was not found...
The CATALINA_HOME environment variable is not defined correctly.
This environment variable is needed to run this program

D:\apache-tomcat-6.0.48-windows-x64\tomcat6\bin>service install Tomcat6

D:\apache-tomcat-6.0.48-windows-x64\tomcat6\bin>SET JAVA_HOME=C:\Program Files\J
ava\jdk1.7.0_80

D:\apache-tomcat-6.0.48-windows-x64\tomcat6\bin>SET CATALINA_HOME=D:\apache-tomc
at-6.0.48-windows-x64\tomcat6

D:\apache-tomcat-6.0.48-windows-x64\tomcat6\bin>SET PR_DISPLAYNAME=Tomcat6
Installing the service 'Tomcat6' ...
Using CATALINA_HOME:    "D:\apache-tomcat-6.0.48-windows-x64\tomcat6"
Using CATALINA_BASE:    "D:\apache-tomcat-6.0.48-windows-x64\tomcat6"
Using JAVA_HOME:        "C:\Program Files\Java\jdk1.7.0_80"
Using JRE_HOME:         "C:\Program Files\Java\jdk1.7.0_80\jre"
Using JVM:              "C:\Program Files\Java\jdk1.7.0_80\jre\bin\server\jvm.dl
l"
The service 'Tomcat6' has been installed.

4.卸载Tomcat服务

service.bat remove

提示如下信息卸载成功

D:\apache-tomcat-6.0.48-windows-x64\tomcat6\bin>service remove

D:\apache-tomcat-6.0.48-windows-x64\tomcat6\bin>SET JAVA_HOME=C:\Program Files\J
ava\jdk1.7.0_80

D:\apache-tomcat-6.0.48-windows-x64\tomcat6\bin>SET CATALINA_HOME=D:\apache-tomc
at-6.0.48-windows-x64\tomcat6

D:\apache-tomcat-6.0.48-windows-x64\tomcat6\bin>SET PR_DISPLAYNAME=Tomcat6
Removing the service 'Tomcat6' ...
Using CATALINA_BASE:    "D:\apache-tomcat-6.0.48-windows-x64\tomcat6"
The service 'Tomcat6' has been removed


浏览.发表于:2016-12-21 16:06:36