Windows one-click packaging and deployment of Java programs

  1. Download program Inno Setup

Download link:  InnoSetup  

A free installer for Windows programs, through which you can compress and package the required files into an exe installer, and then decompress it into another environment like an installer

Open the software installation interface as shown in the figure:

app is the running jar package
build is the program that is packaged and then run in the win environment
icon is the icon of the tool
javase is the environment
script is the script that clicks on the desktop to start the program after the packaged program is installed

  1. write script

; xingyulin 2022-03-24  version 1
#define MyApp "hsjUtil"     
#define MyAppName "测试工具"    
#define MyAppVersion "V1.0"           
#define MyAppPublisher "杭州xxx公司"
#define SoftBaseDir "E:\project\haiShiJia\winInstall"
#define SoftInstallDir "D:\HsjSoft"

; 基本配置
[Setup]
AppName={#MyApp}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
;DefaultDirName={pf}\{#MyApp}
DisableProgramGroupPage=yes
OutputDir=.\build
Compression=lzma
SolidCompression=yes
; 软件名称
OutputBaseFilename={#MyAppName}
; 软件图标
SetupIconFile={#SoftBaseDir}\icon\hsj.ico
; 默认安装路径
DefaultDirName={#SoftInstallDir}
[Files]
Source: "{#SoftBaseDir}\javaSE1.8\jre8\*"; DestDir: "{app}\jre"; Flags: recursesubdirs
Source: "{#SoftBaseDir}\app\*"; DestDir: "{app}\app"; Flags: recursesubdirs
Source: "{#SoftBaseDir}\script\*"; DestDir: "{app}\script"; Flags: recursesubdirs
[Icons]
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\script\start.bat" 
  1. packaged software

Click the run button to package the software

3. Run the installer

Installed directory

A shortcut will be generated on the desktop

Double click to start

4. bat script

@echo off
:loop
tasklist|find /i "demo.jar" >nul 2>&1
if %errorlevel%==0 goto running
echo Starting your jar file...
cd /d "D:\HsjSoft\hsjUtil\jre\bin"
java -jar "D:\HsjSoft\hsjUtil\app\demo.jar"
goto loop

:running
echo Your jar file is already running.
pause

Guess you like

Origin blog.csdn.net/qq_21137441/article/details/129749073