1.安装工具:exe4j,resource_hacker,Inno Setup5 编译器
注意事项:
1.项目打包成可执行的jar包,项目启动类要改名为Application,不然无法启动,会找不到启动类
2.使用exe4j打包时 jre路径放到与输出exe同级目录下,在用iss打包
2.exe4j打包
最好是先破解,否则运行软件会弹框
3. exe输出路径
配置最小内存128m,最大内存256m
建议跟此配置一模一样,否则打包完成运行在无java环境会提示报错
然后直接点10,生成exe,此时exe还不可安装执行
3.使用resource_hacker修改Inno Setup权限
修改Inno Setup权限,打开安装位置找到文件SetupLdr.e32,修改对应内容为requireAdministrator,点击绿色三角形运行后保存
同样会生成一个original.e32可以删除
4 编写Inno Setup完成打包工作
; 脚本由 Inno Setup 脚本向导 生成!
; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档!
#define MyAppName "test"
#define MyAppVersion "0.0.1"
#define MyAppPublisher "xx科技有限有限公司"
#define MyAppURL "www.baidu.com"
#define MyAppExeName "test.exe"
#define MyAppIco "checkwwwc.ico"
#define MyJreName "jre1.8.0_431"
[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (生成新的GUID,点击 工具|在IDE中生成GUID。)
AppId={{4B3D5B77-2288-46C5-AA01-B60955B1AE65}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
; 安装默认路径C:\Program Files (x86)\simutool
DefaultDirName={pf}\simutool
DisableProgramGroupPage=yes
OutputDir=D:\out
OutputBaseFilename=test
;图标路径
SetupIconFile=D:\out\test.ico
;压缩格式lzma2或者是zip
Compression=zip
SolidCompression=yes
[Languages]
Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"
[Tasks]
;桌面图标
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1
;开机启动询问框,自动勾选
Name: "startupicon"; Description: "开机启动"; GroupDescription: "{cm:AdditionalIcons}";
[Files]
Source: "exe4j输出路径\test.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "inno Setup输出路径\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; 读取jre
Source: "exe4j输出路径\jre1.8.0_431\*"; DestDir: "{app}\{#MyJreName}"; Flags: ignoreversion recursesubdirs createallsubdirs
; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”
[Icons]
Name: "{commonprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
; 将快捷方式添加到电脑所有用户的桌面
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
; 将快捷方式添加到电脑所有用户的 [开始菜单-程序]
Name: "{commonstartup}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: startupicon
; 注: 下边这一行让安装的时候自动生成快捷方式
Name: "{userdesktop}\{#MyAppName}";Filename: "{app}\{#MyAppExeName}"; WorkingDir: "{app}";IconFilename: "{app}\{#MyAppIco}"
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
[UninstallRun]
; 卸载前杀掉进程
Filename: taskkill;Parameters:"/t /f /im {#MyAppExeName}";Flags: runhidden
如果没法实现开机自启动,请看你安装后的应用是否带小盾,如果有则无法开机自启动,请用resource_hacker修改exe安装包权限,改为非管理员权限即可。
如果出现无java环境运行失败,请检查inno Setup打包后安装的路径是否带jre,不带请检查上述脚本