springboot,javaweb项目打包成exe在windows下一键安装 jdk+mysql+chrome,安装成功运行项目

我们公司有一个web项目,但是有一个需求是这个项目有时候要安装到客户的本地机器,或者局域网内,大家知道,web项目前期安装比较复杂,对于普通的无技术人员,还是比较麻烦的,就需要公司的技术支持去安装,比较耗费人力,想做成傻瓜式的,交给客户,直接一直“下一步”,安装完成并启动就可以,类似桌面应用的exe安装文件。下面就是具体安装操作。

目录

1.安装Inno steup

Inno setup 是一个免费的windows安装程序制作软件.windows 98,2000,XP,NT4.0,Me以及更高的版本均可使用,资源在下面网盘下载。
链接:https://pan.baidu.com/s/1uxtN_jOVhK8fydRcPPtAgQ
提取码:6eih

一直“下一步”安装完成。

2.下载MySQL

打开MySQL官网,https://www.mysql.com/
在这里插入图片描述
往页面底部下拉,点击选择红色勾选的
在这里插入图片描述
进入如下页面,点击红色勾选的,进入绿色免费版本
在这里插入图片描述
根据自己系统,选择32位或者64位压缩包,点击download下载
在这里插入图片描述

3.下载jdk

这个网上太多了,自己去找吧,我就不说明了。将下载后jdk进行安装,最后需要的是安装后的文件夹。

4.下载exe4j

我上传到云盘了

链接:https://pan.baidu.com/s/1q-N76ZI2xk3wdJomi1AU9Q
提取码:rktr
复制这段内容后打开百度网盘手机App,操作更方便哦

5.下载chrome

我把免安装包上传到云盘了

链接:https://pan.baidu.com/s/1-AM7MAgbLn0xbomjV-6ZAg
提取码:xpi1

6.配置实施

6.1 新建一个文件夹,里面放需要的文件,这些都是上面那些步骤下载好的直接复制过来,Chrome-bin,mysql,图标,我的里面内容比较多不一定适合你。Chrome-bin是浏览器安装包不需要做改动,如果你不需要打包浏览器,就不需要这个了,最后面要讲的启动项删除启动浏览器的命令就好。
在这里插入图片描述

6.2 在mysql里面新建或者修改my.ini文件和myini.bat文件:
在这里插入图片描述
my.ini文件内容如下

# MySQL Server Instance Configuration File
# ----------------------------------------------------------------------
# Generated by the MySQL Server Instance Configuration Wizard
# Installation Instructions
# ----------------------------------------------------------------------
# On Linux you can copy this file to /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options
# (@localstatedir@ for this installation) or to
# ~/.my.cnf to set user-specific options.
# On Windows you should keep this file in the installation directory 
# of your server (e.g. C:\Program Files\MySQL\MySQL Server X.Y). To
# make sure the server reads the config file use the startup option
# "--defaults-file". 
#
# To run run the server from the command line, execute this in a 
# command line shell, e.g.
# mysqld --defaults-file="D:\test\mysql-5.7.24-winx64\my.ini"
#
# To install the server as a Windows service manually, execute this in a 
# command line shell, e.g.
# mysqld --install MySQLXY --defaults-file="D:\test\mysql-5.7.24-winx64\my.ini"
#
# And then execute this in a command line shell to start the server, e.g.
# net start MySQLXY
#
# Guildlines for editing this file
# ----------------------------------------------------------------------
#
# In this file, you can use all long options that the program supports.
# If you want to know the options a program supports, start the program
# with the "--help" option.
#
# More detailed information about the individual options can also be
# found in the manual.
#
# CLIENT SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#
[client]
port=3306
[mysql]
default-character-set=utf8
# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this 
# file.
[mysqld]
# The TCP/IP Port the MySQL Server will listen on
port=3306
#这里是配置mysql的安装目录,当然,在Inno Setup中会将其替换成最终安装路径
basedir="C:/ProgramData/MySQL/mysql-5.7.15-winx64"
#这里是配置mysql的数据库存放目录,当然,在Inno Setup中会将其替换成最终存放路径
datadir="C:/ProgramData/MySQL/mysql-5.7.15-winx64/data/"
secure_file_priv=""
# The default character set that will be used when a new schema or table is
# created and no character set is defined
character-set-server=utf8
# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB
# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
# The maximum amount of concurrent sessions the MySQL server will
# allow. One of these connections will be reserved for a user with
# SUPER privileges to allow the administrator to login even if the
# connection limit has been reached.
max_connections=100
# Query cache is used to cache SELECT results and later return them
# without actual executing the same query once again. Having the query
# cache enabled may result in significant speed improvements, if your
# have a lot of identical queries and rarely changing tables. See the
# "Qcache_lowmem_prunes" status variable to check if the current value
# is high enough for your load.
# Note: In case your tables change very often or if your queries are
# textually different every time, the query cache may result in a
# slowdown instead of a performance improvement.
query_cache_size=32M
# The number of open tables for all threads. Increasing this value
# increases the number of file descriptors that mysqld requires.
# Therefore you have to make sure to set the amount of open files
# allowed to at least 4096 in the variable "open-files-limit" in
# section [mysqld_safe]
table_open_cache=256
# Maximum size for internal (in-memory) temporary tables. If a table
# grows larger than this value, it is automatically converted to disk
# based table This limitation is for a single table. There can be many
# of them.
tmp_table_size=35M
# How many threads we should keep in a cache for reuse. When a client
# disconnects, the client's threads are put in the cache if there aren't
# more than thread_cache_size threads from before.  This greatly reduces
# the amount of thread creations needed if you have a lot of new
# connections. (Normally this doesn't give a notable performance
# improvement if you have a good thread implementation.)
thread_cache_size=8
#*** MyISAM Specific options
# The maximum size of the temporary file MySQL is allowed to use while
# recreating the index (during REPAIR, ALTER TABLE or LOAD DATA INFILE.
# If the file-size would be bigger than this, the index will be created
# through the key cache (which is slower).
myisam_max_sort_file_size=100G
# If the temporary file used for fast index creation would be bigger
# than using the key cache by the amount specified here, then prefer the
# key cache method.  This is mainly used to force long character keys in
# large tables to use the slower key cache method to create the index.
myisam_sort_buffer_size=69M
# Size of the Key Buffer, used to cache index blocks for MyISAM tables.
# Do not set it larger than 30% of your available memory, as some memory
# is also required by the OS to cache rows. Even if you're not using
# MyISAM tables, you should still set it to 8-64M as it will also be
# used for internal temporary disk tables.
key_buffer_size=50M
# Size of the buffer used for doing full table scans of MyISAM tables.
# Allocated per thread, if a full scan is needed.
read_buffer_size=64K
read_rnd_buffer_size=256K
# This buffer is allocated when MySQL needs to rebuild the index in
# REPAIR, OPTIMZE, ALTER table statements as well as in LOAD DATA INFILE
# into an empty table. It is allocated per thread so be careful with
# large settings.
sort_buffer_size=256K
#*** INNODB Specific options ***
# Use this option if you have a MySQL server with InnoDB support enabled
# but you do not plan to use it. This will save memory and disk space
# and speed up some things.
#skip-innodb
# Additional memory pool that is used by InnoDB to store metadata
# information.  If InnoDB requires more memory for this purpose it will
# start to allocate it from the OS.  As this is fast enough on most
# recent operating systems, you normally do not need to change this
# value. SHOW INNODB STATUS will display the current amount used.
#innodb_additional_mem_pool_size=14M
# If set to 1, InnoDB will flush (fsync) the transaction logs to the
# disk at each commit, which offers full ACID behavior. If you are
# willing to compromise this safety, and you are running small
# transactions, you may set this to 0 or 2 to reduce disk I/O to the
# logs. Value 0 means that the log is only written to the log file and
# the log file flushed to disk approximately once per second. Value 2
# means the log is written to the log file at each commit, but the log
# file is only flushed to disk approximately once per second.
innodb_flush_log_at_trx_commit=1
# The size of the buffer InnoDB uses for buffering log data. As soon as
# it is full, InnoDB will have to flush it to disk. As it is flushed
# once per second anyway, it does not make sense to have it very large
# (even with long transactions).
innodb_log_buffer_size=1M
# InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and
# row data. The bigger you set this the less disk I/O is needed to
# access data in tables. On a dedicated database server you may set this
# parameter up to 80% of the machine physical memory size. Do not set it
# too large, though, because competition of the physical memory may
# cause paging in the operating system.  Note that on 32bit systems you
# might be limited to 2-3.5G of user level memory per process, so do not
# set it too high.
innodb_buffer_pool_size=96M
# Size of each log file in a log group. You should set the combined size
# of log files to about 25%-100% of your buffer pool size to avoid
# unneeded buffer pool flush activity on log file overwrite. However,
# note that a larger logfile size will increase the time needed for the
# recovery process.
innodb_log_file_size=20M
# Number of threads allowed inside the InnoDB kernel. The optimal value
# depends highly on the application, hardware as well as the OS
# scheduler properties. A too high value may lead to thread thrashing.
innodb_thread_concurrency=180

myini.bat文件内容如下,目的是当你的软件用户可以自定义安装路径时,如下配置也是动态可变的,如果你的软件用户不能自定义路径,就需要在my.ini文件里面定义好

echo
set CURRENT_DIR=%CD%
set CURRENT_DIR=%CURRENT_DIR:\=\\%
echo basedir="%CURRENT_DIR%\\">>my.ini
echo datadir="%CURRENT_DIR%\\data\\">>my.ini
echo secure-file-priv="%CURRENT_DIR%\\Uploads\\">>my.ini

在bin文件夹下新建mysql_init.bat
在这里插入图片描述
内容如下

sc delete mysql

cd /d %~dp0

"%cd%\mysqld.exe" --initialize-insecure --user=mysql --console

echo -----mysql init succee-----

cd ..

set "MYSQL_HOME=%cd%"

cd bin

mysqld install mysql --defaults-file="%MYSQL_HOME%\my.ini"

echo -----mysql service install succee-----

net start mysql

sc config mysql start= auto

net stop mysql


net start mysql
echo 安装完毕

cd ..

"%cd%\bin\mysqladmin" -u root password root
echo 修改密码完毕

"%cd%\bin\mysql.exe" -uroot -proot < "%cd%\sql\creatdatebase.sql"
"%cd%\bin\mysql.exe" -uroot -proot < "%cd%\sql\creattable.sql"
echo 建表完毕

echo 建立新用户完毕

在sql文件夹下放置项目所需的创建数据库和创建表信息,创建数据库和创建表的sql要分开,如下所示
在这里插入图片描述
下面举个例子,creatdatebase.sql内容
在这里插入图片描述
creattable.sql内必须要有数据库的名字
在这里插入图片描述

6.3 将java安装根路径下的jre复制到你新建的文件夹下的web文件夹下,web文件夹的名字是我自己起的,你可以自定义,但是自定义后,后面的命令也需要改,所以要是不熟悉就完全按照我的来。
在这里插入图片描述
6.4.再新建一个jre文件夹,和上面的install文件夹完全区别,我在桌面上建的,里面放你项目启动时需要的文件,比如我的需要一个config文件,alert.wav等,你根据自己的情况来,必要的文件就是jre,jre也是复制过来。
然后把你的项目jar复制过来,利用exe4j工具新建一个exe4j的文件,新建的时候配置所需的内容,具体使用请看我的文章,exe4j将jar包转为exe文件,https://blog.csdn.net/qq_31683033/article/details/111830313,最后生成一个exe文件。先双击试试看能不能运行成功,如果不能成功,重复上述文章的步骤,一点一点尝试,如果成功,就把exe文件复制到刚才的web文件夹下。
在这里插入图片描述

6.5 启动服务脚本start.bat
我的文件夹下有一个start.bat文件
在这里插入图片描述
内容如下,分别是用来启动几个文件的,根据名字和我的截图你能看的出来都有什么,HQserver也是我的项目种的,你的项目要是没有别的东西,就只有上一步生成的exe。

@echo off
start "" "%cd%\web\\switchgear.exe"
start "" "%cd%\web\HQServer.exe"
ping -n 3 127.0.0.1>nul
start "" "%cd%\Chrome-bin\chrome.exe" http://localhost:9000/hqgd
taskkill /f /im start.exe
exit

利用bat to exe工具把start.bat转成start.exe文件。
在这里插入图片描述
6.6卸载文件
在web文件夹下新建uninstall.bat文件
在这里插入图片描述
内容如下

taskkill /f /im switchgear.exe
taskkill /f /im chrome.exe
taskkill /f /im start.exe
taskkill /f /im HQServer.exe
@echo off
echo 获取Administrator权限
cacls.exe "%SystemDrive%\System Volume Information" >nul 2>nul
if %errorlevel%==0 goto Admin
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
echo Set RequestUAC = CreateObject^("Shell.Application"^)>"%temp%\getadmin.vbs"
echo RequestUAC.ShellExecute "%~s0","","","runas",1 >>"%temp%\getadmin.vbs"
echo WScript.Quit >>"%temp%\getadmin.vbs"
"%temp%\getadmin.vbs" /f
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
exit
 
:Admin
echo 成功取得Administrator权限
 
echo 检测MySQL状态
for /f "skip=3 tokens=4" %%i in ('sc query MySQL') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
    echo MySQL服务运行中
	echo 关闭MySQL
    sc stop MySQL
	echo 删除MySQL
    sc delete mysql
) 
echo MySQL删除成功
exit

6.7 iss文件配置
在这里插入图片描述

用inno setup打开一个新文件,可以配置你自己的需要,如果有不完善的可以参考下面的内容

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "HQ-TDMS"
#define MyAppVersion "v1.1.0.16"
#define MyAppPublisher "HERCH"
#define MyAppURL "http://localhost:9000/hqgd"
#define MyAppExeName "start.exe"

[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.)
AppId={{BC462E9F-B026-4087-A453-34D761815E9C}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName=C:\HQ-TDMS\{#MyAppName}
;DisableDirPage=yes
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=C:\Users\yr\Desktop\webinstall\64\Output
OutputBaseFilename=switchgear_ChongQing_x64_v1.1.0.16
SetupIconFile=C:\Users\yr\Desktop\webinstall\64\Temperature.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern

[Languages]
Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "C:\Users\yr\Desktop\webinstall\64\start.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\yr\Desktop\webinstall\64\Chrome-bin\*"; DestDir: "{app}\Chrome-bin"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "C:\Users\yr\Desktop\webinstall\64\mysql-5.7.15-winx64\*"; DestDir: "{app}\mysql-5.7.15-winx64"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "C:\Users\yr\Desktop\webinstall\64\web\*"; DestDir: "{app}\web"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "C:\Users\yr\Desktop\webinstall\64\initStart.bat"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
Filename: "{app}\mysql-5.7.15-winx64\myini.bat";
Filename: "{app}\mysql-5.7.15-winx64\bin\mysql_init.bat";                            
Filename: "{app}\initStart.bat";                       
[UninstallRun]
Filename: "{app}\web\uninstall.bat";

[UninstallDelete]
  
Type:filesandordirs;Name:"{app}\mysql-5.7.15-winx64"
Type:filesandordirs;Name:"{app}\Chrome-bin"
Type:filesandordirs;Name:"{app}\web"

生成的文件会输出在output文件夹下,那个就是打包好的,可以直接双击运行了。

如果疑问,联系QQ:736812983

  • 1
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
JavaWeb项目打包WAR(Web Application Archive)文件是部署和发布项目的一种常见方式。WAR文件是一种压缩文件,包含了用于运行和部署Web应用程序所需的所有资源和文件。 步骤如下: 1. 创建一个JavaWeb项目,并编写代码和配置文件,确保项目能够正常运行。 2. 打开项目的构建工具(如Maven或Gradle)的配置文件(pom.xml或build.gradle),添加相关的插件和依赖项。 3. 添加构建配置,以便将项目打包WAR文件。在Maven中,可以在pom.xml中添加以下配置: ```xml <packaging>war</packaging> ``` 在Gradle中,可以在build.gradle中添加以下配置: ```groovy apply plugin: 'war' ``` 4. 配置项目的部署描述符(web.xml)。这个文件位于WEB-INF目录下,用于配置Servlet、Filter和其他Web应用程序相关的参数。确保web.xml文件的路径和内容正确。 5. 在终端或命令行界面中,切换到项目根目录,并执行项目的构建命令。例如,在Maven中,可以使用以下命令构建项目: ``` mvn clean package ``` 在Gradle中,可以使用以下命令构建项目: ``` gradle clean war ``` 6. 构建完后,会在项目的目录中生一个WAR文件(以项目名称命名),路径类似于target/项目名称.war。 7. 将生的WAR文件拷贝到服务器上的Tomcat或其他支持JavaWeb项目部署的应用服务器的webapps目录中。 8. 启动服务器,项目会被自动部署并开始运行。 通过以上步骤,将JavaWeb项目打包WAR文件后,可以方便地进行部署和发布,以便在服务器上运行Web应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值