Windows 10 +Tomcat 8 + jdk 1.8 + 服务注册 + bat自动安装 配置
Windows 10 +Tomcat 8 + jdk 1.8 + 服务注册 + 修改服务启动类型 + bat自动安装 配置方法
1、 从官网下载jdk1.8 和Tomcat 8安装包
jdk-8u172-windows-x64.exe (网址:http://www.oracle.com/technetwork/java/javase/downloads/index.html)
apache-tomcat-8.5.32-windows-x64.zip (网址:http://tomcat.apache.org/)
2、 制作jdk免安装包
- 双击jdk-8u172-windows-x64.exe安装软件
这一步不点击更改,直接点击下一步。
安装完成后,把C:\Java\目录完整复制,就可以得到JDK的免安装包
3、 Tomcat 8 的安装包解压即可使用
4、 整理安装包,编写bat文件
安装包目录架构如下:
C:\tomcat
├─tomcat
│ ├─apache-tomcat-8.5.32 (Tomcat 8.5.32 解压目录)
│ │ ├─bin (将catalina.bat、service.bat、startup.bat、shutdown.bat 四个文件拷贝到tomcat_bin文件夹下,拷贝后源文件删除)
│ │ ├─conf
│ │ ├─java-1.8 (复制过来的JDK 1.8 安装包)
│ │ ├─lib
│ │ ├─logs
│ │ ├─temp
│ │ ├─webapps
│ │ └─work
├─tomcat_bin (存放home.bak、catalina.bak.bat、service.bak.bat、startup.bak.bat、shutdown.bak.bat 文件)
├─install.bat (自动安装脚本)
└─confing.txt (自动安装脚本执行完成后自动生成,存放安装路径等信息)
5、 文件说明
tomcat_bin 文件夹下文件在install.bat中会用到,其中 home.bak文件内容为空,catalina.bak.bat、service.bak.bat、startup.bak.bat、shutdown.bak.bat四个文件分别是从bin文件中拷贝过来的四个文件删除第一行(@echo off)后的备份,源文件删除。
6、 install.bat 文件内容
echo off
rem Get the current path
set C_PATH=%CD%
rem Get the installation path
set/p "I_PATH=Please enter the installation path:"
rem Check whether the installation path exists.
rem If the path already exists ,exit.
rem if no exists,creation installation path.
if exist %I_PATH% goto I_PATH_EXIT
if not exist %I_PATH% goto I_PATH_ONT_EXIT
:I_PATH_EXIT
echo %I_PATH% Already exist, please replace
set/p "I_PATH=Please enter the installation path:"
if exist %I_PATH% goto I_PATH_EXIT
if not exist %I_PATH% goto I_PATH_ONT_EXIT
:I_PATH_ONT_EXIT
mkdir %I_PATH%
mkdir %I_PATH%\tomcat
rem echo Copy the file to the installation directory
rem xcopy directory ,copy file
xcopy %C_PATH%\tomcat %I_PATH%\tomcat /s
echo @echo off>%C_PATH%\tomcat_bin\home.bat
echo set CATALINA_HOME=%I_PATH%\tomcat\apache-tomcat-8.5.32>>%C_PATH%\tomcat_bin\home.bat
echo set JAVA_HOME=%I_PATH%\tomcat\apache-tomcat-8.5.32\java-1.8>>%C_PATH%\tomcat_bin\home.bat
type %C_PATH%\tomcat_bin\home.bat %C_PATH%\tomcat_bin\catalina.bak.bat >> %C_PATH%\tomcat_bin\catalina.bat
type %C_PATH%\tomcat_bin\home.bat %C_PATH%\tomcat_bin\service.bak.bat >> %C_PATH%\tomcat_bin\service.bat
type %C_PATH%\tomcat_bin\home.bat %C_PATH%\tomcat_bin\startup.bak.bat >> %C_PATH%\tomcat_bin\startup.bat
type %C_PATH%\tomcat_bin\home.bat %C_PATH%\tomcat_bin\shutdown.bak.bat >> %C_PATH%\tomcat_bin\shutdown.bat
move %C_PATH%\tomcat_bin\catalina.bat %I_PATH%\tomcat\apache-tomcat-8.5.32\bin\
move %C_PATH%\tomcat_bin\service.bat %I_PATH%\tomcat\apache-tomcat-8.5.32\bin\
move %C_PATH%\tomcat_bin\startup.bat %I_PATH%\tomcat\apache-tomcat-8.5.32\bin\
move %C_PATH%\tomcat_bin\shutdown.bat %I_PATH%\tomcat\apache-tomcat-8.5.32\bin\
@ timeout 5
rem Register as a service
call %I_PATH%\tomcat\apache-tomcat-8.5.32\bin\service.bat install
@ timeout 3
sc config Tomcat8 start= auto
@ timeout 3
net start Tomcat8
rem Generate configuration file
echo 系统安装路径:%I_PATH%\tomcat > %C_PATH%\confing.txt
echo 系统启动命令:net start Tomcat8 >> %C_PATH%\confing.txt
echo 系统关闭命令:net stop Tomcat8 >> %C_PATH%\confing.txt
echo 可以通过服务启动或关闭系统(已经配置开机自启动 )>> %C_PATH%\confing.txt
echo 系统服务安装命令:%I_PATH%\tomcat\apache-tomcat-8.5.32\bin\service.bat install >> %C_PATH%\confing.txt
echo 系统服务卸载命令:%I_PATH%\tomcat\apache-tomcat-8.5.32\bin\service.bat remove >> %C_PATH%\confing.txt
pause
7、 双击install.bat,输入要安装的路径,即可自动安装
c:\app 为安装路径
至此,自动安装成功,并已经启动
8、 本机访问测试
9、 查看confing.txt的内容
系统安装路径:c:\app\tomcat
系统启动命令:net start Tomcat8
系统关闭命令:net stop Tomcat8
可以通过服务启动或关闭系统(已经配置开机自启动 )
系统服务安装命令:c:\app\tomcat\apache-tomcat-8.5.32\bin\service.bat install
系统服务卸载命令:c:\app\tomcat\apache-tomcat-8.5.32\bin\service.bat remove
10、 参考文档
https://www.jb51.net/article/5828.htm BAT文件语法和技巧(bat文件的编写及使
用)
https://blog.csdn.net/ttx_laughing/article/details/52919456 关于tomcat注册成一个服务,并修改启动类型