windows一键安装Javaweb项目

所需工具

Inno Setup 编译器(自行百度下载)
tomcat8.0解压版
JDK8.0解压版
mysql8.0.15解压版

Inno Setup打包文本:

其中xxx部分可以自定义配置,
安装部署的源文件路径为你的解压包所在的路径
软件图标为你的ioc图标所在位置
程序安装成功后执行以下服务脚本,这几个脚本后面会给出
快捷键,根据需要设置,我这里设置的是一个网页和tomcat的启动项

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "xxx平台"        
#define MyAppVersion "1.0"           
#define MyAppPublisher "xxx有限公司"
#define MyAppURL "https://blog.csdn.net/menofgod"
 
; 基本配置
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
; 单独标识,可以通过innosetup-QSP-5.6.1.exe 工具自动生成
AppId={{F4210312-A665-49E6-A943-E3B01581A3AF}}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
; 默认安装路径
DefaultDirName=E:\onekey
DefaultGroupName={#MyAppName}
; 软件名称
OutputBaseFilename=隧道监控系统
; 软件图标
SetupIconFile=H:\javaWeb一键部署\Tunnel\favicon.ico 
; 压缩方式  
Compression=lzma
; yes 可以使文件更小
SolidCompression=yes
; 必需有管理员权限才能安装
PrivilegesRequired=admin
; 安装密码
;Password=itdragon
; 开启加密,可能还需要一个dll文件
;Encryption=yes
 
; 语言配置 
[Languages]
Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"
 
; 安装文件
[Files]
; 安装部署的源文件路径
Source: "H:\javaWeb一键部署\Tunnel\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
 
; 快捷键
[Icons]
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}" 
Name: "{commondesktop}\隧道监控系统前台"; Filename: http://localhost:8080/Tunnel/login.html
Name: "{commondesktop}\启动服务"; Filename: "{app}\tomcat8\bin\startup.bat"
 
; 程序安装成功后执行以下服务脚本
[Run]     
Filename: "{app}\tomcat8\bin\tomcat_start.bat";
Filename: "{app}\mysql\install.bat";
Filename: "{app}\mysql\executesql.bat";

文件位置

mysql与tomcat以及ico图标位于同一级目录
在这里插入图片描述
在tomcat的bin目录下新建一个java目录,将jdk文件放在java目录下

将你的项目放到tomcat下的webapps目录下(war包、前台代码)
在这里插入图片描述

tomcat启动环境配置

打卡bin目录下的startup.bat在@echo off后面加上:

set LOCA_LHOME=%~dp0
set JRE_HOME=%LOCA_LHOME%java\jre8

在tomcat文件加入批处理文件tomcat_start.bat,这个文件是用来安装完成后启动tomcat的,在我的实验中没有起到作用。

mysql配置

将提供的my.ini文件放在mysql文件夹下
my.ini:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

character_set_server=utf8

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
#basedir = .....
#datadir = .....
port = 3306
# server_id = .....


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

[client]
port=3306
default-character-set=utf8
[mysql]
default-character-set=utf8

将install.bat、password.bat、executesql.bat放在mysql文件夹下,install.bat的作用是添加mysql服务,password.bat的作用是修改mysql的初始密码,executesql.bat的作用是执行sql语句
install.bat:

@echo off

rem **********************************MySQL环境变量部署*****************************************
rem cd /d %~dp0
rem del /F %cd%\my.ini
rem echo 删除完成
rem echo [client]>> my.ini
rem echo port = 3306>> my.ini
rem echo default-character-set=utf8>>my.ini
rem echo [mysqld]>> my.ini
rem echo collation-server=utf8_general_ci>>my.ini
rem echo log-error=%cd:\=\%\error>>my.ini
rem echo character_set_server=utf8>>my.ini
rem echo default_storage_engine=MYISAM>> my.ini
rem echo basedir=%cd:\=\%\>>my.ini
rem echo datadir=%cd:\=\%\data>> my.ini
rem echo innodb_data_file=ibdata1:50M;ibdata2:10M:autoextend>> my.ini
rem echo transaction-isolation=READ-COMMITTED>> my.ini
rem echo port=3306>> my.ini
rem echo max_allowed_packet=64M>> my.ini
rem echo tmp_table_size=64M>> my.ini
rem echo my.ini生成成功
cd /d %~dp0


echo "注册MySql服务开始"
echo "停止已存在的服务MySQL"
net stop MySQL
echo "删除已存在的服务MySQL"
sc delete MySQL


echo "删除服务执行文件项"
rem REG Delete HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MySQL /v ImagePath /f
%~dp0bin\mysqld.exe -install
echo "添加服务执行文件项"
rem REG add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MySQL /v ImagePath /t REG_EXPAND_SZ /d "%cd%\bin\MySqld.exe --defaults-file=\"%cd%\my.ini\" MySQL" /f
net start mysql
rem %~dp0bin\mysqladmin.exe -u root -papgkh+u!j4cF root password root    //此部分 为 修改mysql密码
password.bat
rem **********************************数据执行*****************************************
rem executesql.bat
rem pause

password.bat
“%~dp0bin\mysqladmin.exe” -u root -papgkh+u!j4cF password root为修改mysql密码,xxx为你自己想要设置的密码,-papgkh+u!j4cF为原始密码,这里是我运行命令生产data文件夹时生成的,不需要进行修改

@echo off
cd /d %~dp0
"%~dp0bin\mysqladmin.exe" -u root -papgkh+u!j4cF password xxx
rem pause

executesql.bat
执行sql语句,my.sql与update.sql是特定语句,后面提供。tunnel_monitor_system.sql是你自己数据库的到处,其中在
“%mysql_path%mysql” -u%user_mysql% -p%password_mysql% tunnel_monitor_system<tunnel_monitor_system.sql中<前的tunnel_monitor_system为数据库的名称,根据自己数据库的名称进行修改。

@echo off

set currpath=%~dp0
set mysql_path=%currpath%\bin\
set user_mysql=root
set password_mysql=root
"%mysql_path%mysql" -u%user_mysql% -p%password_mysql% <my.sql
echo "create database my successful!"
"%mysql_path%mysql" -u%user_mysql% -p%password_mysql% <update.sql
echo "create database update successful!"
"%mysql_path%mysql" -u%user_mysql% -p%password_mysql% tunnel_monitor_system<tunnel_monitor_system.sql
echo "create database update successful!"
pause

my.sql
my.sql的作用是修改mysql服务启动后无法使用密码登录(编码格式不正确)以及无法使用ip登录的问题,不需要修改直接可以使用

use mysql;
select 'host' from user where user='root';
update user set host = '%' where user ='root';
flush privileges;
select 'host'   from user where user='root';
ALTER USER 'root'@'%' IDENTIFIED BY 'root' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
FLUSH PRIVILEGES;

update.sql
创建数据库,tunnel_monitor_system为你的数据库名,自行修改。

CREATE DATABASE tunnel_monitor_system;

妥了,使用Inno Setup打包,双击安装完美。
处理文件下载地址:
https://download.csdn.net/download/u014085188/11081539

相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页