SpringBoot项目打包为exe,一键运行,整合mysql+jre | 您所在的位置:网站首页 › jdk没有jre文件怎么导入mysql驱动 › SpringBoot项目打包为exe,一键运行,整合mysql+jre |
SpringBoot项目打包(exe+jre+mysql)一键安装,吐血总结,实测可用 一、打包- 1、将SpringBoot项目打包为jar包(数据库配置建议改为本地,因后续数据库安装在本地) ( 以下为pom文件) jar org.apache.maven.plugins maven-compiler-plugin 1.8 1.8 org.springframework.boot spring-boot-maven-plugin repackage1.1 修改完成后,使用idea自带的打包工具打包,maven package,生成jar包; 1.2 该jar包可直接使用Java -jar 运行(jar包位于工程target目录下)。 二、下载exe4j工具
2.1 百度找一个exe4j的注册码 2.2 Next选择第二个“JAR in EXE mode” 2.3 Next填写名称及生成位置 2.4 选择操作系统32位或者64位
mysql_stop.bat cd %~dp0 net stop mysql sc delete mysql-job "%cd%\mysqld.exe" -remove mysql echo mysql卸载完成 exit3.3 打开Info Setup,选择第二个 3.5 继续下一步直到选择文件输出路径 3.8 修改后脚本 ; 脚本由 Inno Setup 脚本向导 生成! ; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! #define MyAppName "我的程序" #define MyAppVersion "1.5" #define MyAppPublisher "我的公司" #define MyAppURL "http://www.example.com/" #define MyAppExeName "myExe.exe" #define MysqlName "mysql-8.0.27-winx64" [Setup] ; 注: AppId的值为单独标识该应用程序。 ; 不要为其他安装程序使用相同的AppId值。 ; (若要生成新的 GUID,可在菜单中点击 "工具|生成 GUID"。) AppId={{26838C49-A6E9-440C-9DA3-0DFA2352119C} AppName={#MyAppName} AppVersion={#MyAppVersion} ;AppVerName={#MyAppName} {#MyAppVersion} AppPublisher={#MyAppPublisher} AppPublisherURL={#MyAppURL} AppSupportURL={#MyAppURL} AppUpdatesURL={#MyAppURL} DefaultDirName={autopf}\{#MyAppName} DisableProgramGroupPage=yes ; 以下行取消注释,以在非管理安装模式下运行(仅为当前用户安装)。 ;PrivilegesRequired=lowest OutputDir=C:\Users\wkwyM\Desktop\jarTest OutputBaseFilename=线缆1.2 SetupIconFile=C:\Users\wkwyM\Desktop\jarTest\Tyrannosaurus rex.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\wkwyM\Desktop\jarTest\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion Source: "C:\Users\wkwyM\Desktop\jarTest\jre\*"; DestDir: "{app}\jre"; Flags: ignoreversion recursesubdirs createallsubdirs Source: "C:\Users\wkwyM\Desktop\jarTest\var\*"; DestDir: "c:\var"; Flags: ignoreversion recursesubdirs createallsubdirs Source: "C:\Users\wkwyM\Desktop\jarTest\{#MysqlName}\*"; DestDir: "{app}\{#MysqlName}"; Flags: ignoreversion recursesubdirs createallsubdirs ; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion” [Icons] Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon [Run] Filename: "{app}\{#MysqlName}\bin\mysql_init.bat"; Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent [UninstallRun] Filename: "{app}\{#MysqlName}\bin\mysql_stop.bat"; [Code] // 自定义函数,判断软件是否运行,参数为需要判断的软件的exe名称 function CheckSoftRun(strExeName: String): Boolean; // 变量定义 var ErrorCode: Integer; var bRes: Boolean; var strFileContent: AnsiString; var strTmpPath: String; // 临时目录 var strTmpFile: String; // 临时文件,保存查找软件数据结果 var strCmdFind: String; // 查找软件命令 var strCmdKill: String; // 终止软件命令 begin strTmpPath := GetTempDir(); strTmpFile := Format('%sfindSoftRes.txt', [strTmpPath]); strCmdFind := Format('/c tasklist /nh|find /c /i "%s" > "%s"', [strExeName, strTmpFile]); strCmdKill := Format('/c taskkill /f /t /im %s', [strExeName]); bRes := ShellExec('open', ExpandConstant('{cmd}'), strCmdFind, '', SW_HIDE, ewWaitUntilTerminated, ErrorCode); if bRes then begin bRes := LoadStringFromFile(strTmpFile, strFileContent); strFileContent := Trim(strFileContent); if bRes then begin if StrToInt(strFileContent) > 0 then begin if MsgBox(ExpandConstant('{cm:checkSoftTip}'), mbConfirmation, MB_OKCANCEL) = IDOK then begin // 终止程序 ShellExec('open', ExpandConstant('{cmd}'), strCmdKill, '', SW_HIDE, ewNoWait, ErrorCode); Result:= true;// 继续安装 end else begin Result:= false;// 安装程序退出 Exit; end; end else begin // 软件没在运行 Result:= true; Exit; end; end; end; Result :=true; end; // 重复安装检测 function InitializeSetup():boolean; var MykeynotExist:boolean; ResultCode: Integer; uicmd: String; begin MykeynotExist:= true; if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{4A78DE64-0E3F-4EA1-BCE1-7A01E66BC1FF}_is1', 'UninstallString', uicmd) then begin MsgBox('{#MyAppName}已经安装,你确定要先卸载,再安装!', mbInformation, MB_OK) MyKeynotExist:= false; Exec(RemoveQuotes(uicmd), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode); end; Result:= MykeynotExist end; // 卸载时关闭软件 function InitializeUninstall(): Boolean; begin Result := CheckSoftRun('{#MyAppExeName}'); end; procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); begin if CurUninstallStep = usDone then begin //删除 {app} 文件夹及其中所有文件 DelTree(ExpandConstant('{app}'), True, True, True); end; end; [CustomMessages] chinesesimp.checkSoftTip=检测到软件正在运行!%n%n点击"确定"终止软件后继续操作,否则点击"取消"。不同点: 3.9 编译运行,等进度条完成后安装使用即可 3.10 安装完成后不要运行,一定要以管理员身份运行 |
CopyRight 2018-2019 实验室设备网 版权所有 |