概述
1. 下载MySQL、JDK、Tomcat
【MySQL64位】
http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.26-winx64.zip
【MySQL32位】
http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.26-win32.zip
【JDK 64位】
http://download.oracle.com/otn-pub/java/jdk/8u60-b27/jdk-8u60-windows-x64.exe?AuthParam=1441529858_771aeb3e7d7a6230692b72cf748b612f
【JDK 32位】
http://download.oracle.com/otn-pub/java/jdk/8u60-b27/jdk-8u60-windows-i586.exe?AuthParam=1441527399_24e27670f8213dc1f3b5c010921c5810
【Tomcat64位】
http://mirrors.cnnic.cn/apache/tomcat/tomcat-8/v8.0.26/bin/apache-tomcat-8.0.26-windows-x64.zip
【Tomcat32位】
http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.0.26/bin/apache-tomcat-8.0.26-windows-x86.zip
-
解压MySQL、Tomcat,安装JDK
创建如下图的目录结构,jre是从JDK的安装目录(%JAVA_HOME%jre)中拷贝过来的,mysql是直接解压缩下载的MySQL重命名根文件夹得到的,tomcat是直接解压下载的Tomcat重命名根文件夹得到的。
-
MySQL瘦身,解压后删除所有.pdb后缀内容,删除无用文件夹得到如下结构
2. 编写批处理文件
下面是将javaWebConfig.bat拆分介绍,文章最后会附上完整版的javaWebConfig.bat
【javaWebConfig.bat】头部&停止已存在的mysql服务&删除mysql服务
@echo off & setlocal EnableDelayedExpansion
net stop mysql
sc delete mysql
GOTO check80
【javaWebConfig.bat】检查端口占用情况
:check80
echo check port 80...
for /f "tokens=3 delims=:, " %%i in ('netstat -ano') do (
if "%%i" == "80" GOTO 80used
)
GOTO configBegin
:80used
mshta vbscript:CreateObject("Wscript.Shell").popup("端口80被占用,请解除端口占用后重新启动",7,"提示",64)(window.close)
exit /B 2
【javaWebConfig.bat】配置启动mysql
:configBegin
rem config mysql
"%~dp0mysqlbinmysqld" install
echo [mysql]>"%~dp0mysqlmy.ini"
echo default-character-set=utf8>>"%~dp0mysqlmy.ini"
echo [mysqld]>>"%~dp0mysqlmy.ini"
echo port = 3306>>"%~dp0mysqlmy.ini"
echo max_connections=200>>"%~dp0mysqlmy.ini"
echo character-set-server=utf8>>"%~dp0mysqlmy.ini"
echo default-storage-engine=INNODB>>"%~dp0mysqlmy.ini"
echo sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES>>"%~dp0mysqlmy.ini"
echo key_buffer_size = 256M>>"%~dp0mysqlmy.ini"
echo max_allowed_packet = 1M>>"%~dp0mysqlmy.ini"
echo table_open_cache = 256>>"%~dp0mysqlmy.ini"
echo sort_buffer_size = 1M>>"%~dp0mysqlmy.ini"
echo read_buffer_size = 1M>>"%~dp0mysqlmy.ini"
echo read_rnd_buffer_size = 4M>>"%~dp0mysqlmy.ini"
echo myisam_sort_buffer_size = 64M>>"%~dp0mysqlmy.ini"
echo thread_cache_size = 8M>>"%~dp0mysqlmy.ini"
echo query_cache_size = 16M>>"%~dp0mysqlmy.ini"
echo basedir=%~dp0mysql>>"%~dp0mysqlmy.ini"
echo datadir=%~dp0mysqldata>>"%~dp0mysqlmy.ini"
net start mysql
【javaWebConfig.bat】配置启动tomcat
echo @echo off>"%~dp0tomcatbintemp.bat"
echo set JAVA_HOME=%~dp0jdk>>"%~dp0tomcatbintemp.bat"
echo set JRE_HOME=%~dp0jdkjre>>"%~dp0tomcatbintemp.bat"
set j=0
for /f "usebackq delims=""" %%i in ("%~dp0tomcatbinsetclasspath.bat") do (
set /a j+=1
set con!j!=%%i
call set a=%%con!j!%%
if !j! NEQ 1 (echo !a!>>"%~dp0tomcatbintemp.bat")
)
del "%~dp0tomcatbinsetclasspath.bat"
ren "%~dp0tomcatbintemp.bat" setclasspath.bat
echo %~dp0
rem start tomcat
set CATALINA_HOME=%~dp0tomcat
call "%~dp0tomcatbinshutdown.bat"
call "%~dp0tomcatbinstartup.bat"
3. 测试运行
将javaWebConfig.bat放在mysql、tomcat、jdk同目录下,右键以管理员身份运行即可
附:javaWebConfig.bat
@echo off & setlocal EnableDelayedExpansion
rem config prepare
net stop mysql
sc delete mysql
GOTO check80
rem check ports if available
:check80
echo check port 80...
for /f "tokens=3 delims=:, " %%i in ('netstat -ano') do (
if "%%i" == "80" GOTO 80used
)
GOTO check21
:80used
mshta vbscript:CreateObject("Wscript.Shell").popup("端口80被占用,请解除端口占用后重新启动",7,"提示",64)(window.close)
exit /B 2
:check21
echo check port 21...
for /f "tokens=3 delims=:, " %%i in ('netstat -ano') do (
if "%%i" == "21" GOTO 21used
)
GOTO check3131
:21used
mshta vbscript:CreateObject("Wscript.Shell").popup("端口21被占用,请解除端口占用后重新启动",7,"提示",64)(window.close)
exit /B 2
:check3131
echo check port 3131...
for /f "tokens=3 delims=:, " %%i in ('netstat -ano') do (
if "%%i" == "3131" GOTO 3131used
)
GOTO check5151
:3131used
mshta vbscript:CreateObject("Wscript.Shell").popup("端口3131被占用,请解除端口占用后重新启动",7,"提示",64)(window.close)
exit /B 2
:check5151
echo check port 5151...
for /f "tokens=3 delims=:, " %%i in ('netstat -ano') do (
if "%%i" == "5151" GOTO 5151used
)
GOTO configBegin
:5151used
mshta vbscript:CreateObject("Wscript.Shell").popup("端口5151被占用,请解除端口占用后重新启动",7,"提示",64)(window.close)
exit /B 2
rem config tomcat
echo @echo off>"%~dp0tomcatbintemp.bat"
echo set JAVA_HOME=%~dp0jdk>>"%~dp0tomcatbintemp.bat"
echo set JRE_HOME=%~dp0jdkjre>>"%~dp0tomcatbintemp.bat"
set j=0
for /f "usebackq delims=""" %%i in ("%~dp0tomcatbinsetclasspath.bat") do (
set /a j+=1
set con!j!=%%i
call set a=%%con!j!%%
if !j! NEQ 1 (echo !a!>>"%~dp0tomcatbintemp.bat")
)
del "%~dp0tomcatbinsetclasspath.bat"
ren "%~dp0tomcatbintemp.bat" setclasspath.bat
echo %~dp0
rem start tomcat
set CATALINA_HOME=%~dp0tomcat
call "%~dp0tomcatbinshutdown.bat"
call "%~dp0tomcatbinstartup.bat"
最后
以上就是仁爱高跟鞋为你收集整理的windows 打包Java web项目内容实现一键安装1. 下载MySQL、JDK、Tomcat2. 编写批处理文件3. 测试运行的全部内容,希望文章能够帮你解决windows 打包Java web项目内容实现一键安装1. 下载MySQL、JDK、Tomcat2. 编写批处理文件3. 测试运行所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复