Complete JRE Solution for Inno Installation
In order to implement a related JRE solution with the jar application, I created the Inno Setup script, which:
1) copies the JRE to the installation exe
2) execute the equivalent of a terminal command: java -jar myjar.jar using the associated JRE
First I copy the JRE:
#define MyJREPath "C:\Program Files\Java\jre1.8.0_191" [Files] Source: "{#MyJREPath}\*"; DestDir: "{app}\runtime\jre\"; \ Flags: ignoreversion recursesubdirs createallsubdirs;
I adhere to the directory structure agreement shown here: https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/self-contained-packaging.html
To run the java -jar equivalent of myjar.jar:
[Run] Filename: "{app}\runtime\jre\bin\javaw.exe"; Parameters: " -jar myjar.jar"; \ WorkingDir: "{app}\app\"; \ Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; \ Flags: postinstall skipifsilent
(nb java.exe works with the terminal, and javaw.exe works without the terminal)
The shortcut on the desktop should have the correct file name, parameters and working directory:
[Icons] Name: "{commondesktop}\{#MyAppName}"; \ IconFilename: "{app}\app\{#MyAppIcoName}"; \ Filename: "{app}\runtime\jre\bin\javaw.exe"; \ Parameters: " -jar myjar.jar"; \ WorkingDir: "{app}\app\"; \ Tasks: desktopicon [Tasks] Name: "desktopicon"; \ Description: "{cm:CreateDesktopIcon}"; \ GroupDescription: "{cm:AdditionalIcons}"; \ Flags: unchecked
To freeze the cake so that my script processes both related JREs and no related parameters, I use the preprocessor IF statement (duplicated in each section of the script) to check if the script has an empty MyJREPath or not. If MyJREPath is not empty and therefore requires a comprehensive JRE solution, I use the above encoding; alternatively, if a batch solution is not required, then I use the more βnormalβ coding shown in the Inno installation examples or created by their wizard. Here is the IF expression:
#if MyJREPath != "" ; bundled JRE required #else ; bundled JRE not required #endif
Here, most of my script is compiled:
; Script generated by the Inno Setup Script Wizard. ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! ; some more #defines here #define MyAppExeName "javaw.exe" #define MyJREPath "C:\Program Files\Java\jre1.8.0_191" ;#define MyJREPath "" [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=XXXXXXXXXX AppName={#MyAppName} AppVersion={#MyAppVersion} ;AppVerName={#MyAppName} {#MyAppVersion} AppPublisher={#MyAppPublisher} DefaultGroupName={#MyAppPublisher} AppPublisherURL={#MyAppURL} AppSupportURL={#MyAppURL} AppUpdatesURL={#MyAppURL} DefaultDirName={pf}\{#MyDefaultDirName} DisableProgramGroupPage=yes LicenseFile={#MyInnoSetupDir}\system\{#MyLicenseFile} OutputDir={#MyInnoSetupDir} #if MyJREPath != "" ; run app with bundled JRE OutputBaseFilename={#MyAppName}-{#MyAppVersion}-bundledJRE-setup #else ; run app without bundled JRE OutputBaseFilename={#MyAppName}-{#MyAppVersion}-setup #endif SetupIconFile={#MyInnoSetupDir}\{#MyAppIcoName} Compression=lzma SolidCompression=yes AppComments={#MyAppName} AppCopyright={#MyAppCopyright} UninstallDisplayIcon={#MyInnoSetupDir}\{#MyAppIcoName} UninstallDisplayName={#MyAppName} WizardImageStretch=No WizardSmallImageFile={#MyInnoSetupDir}\{#MyAppBmpName} [Languages] Name: "english"; MessagesFile: "compiler:Default.isl" ;Name: "german"; MessagesFile: "compiler:Languages\German.isl" [Tasks] Name: "desktopicon"; \ Description: "{cm:CreateDesktopIcon}"; \ GroupDescription: "{cm:AdditionalIcons}"; \ Flags: unchecked Name: "quicklaunchicon"; \ Description: "{cm:CreateQuickLaunchIcon}"; \ GroupDescription: "{cm:AdditionalIcons}"; \ Flags: unchecked; OnlyBelowVersion: 0,6.1 [Files] ; bundle JRE if required #if MyJREPath != "" Source: "{#MyJREPath}\*"; DestDir: "{app}\runtime\jre\"; \ Flags: ignoreversion recursesubdirs createallsubdirs; #endif ; copy jar and all files Source: "{#MyInnoSetupDir}\*"; DestDir: "{app}\app\"; \ Flags: ignoreversion recursesubdirs createallsubdirs [Icons] #if MyJREPath != "" ; set up icons with bundled JRE Name: "{commonprograms}\{#MyAppName}"; \ IconFilename: "{app}\app\{#MyAppIcoName}"; \ Filename: "{app}\runtime\jre\bin\{#MyAppExeName}"; \ Parameters: " -jar {#MyJarName}"; \ WorkingDir: "{app}\app\" Name: "{commondesktop}\{#MyAppName}"; \ IconFilename: "{app}\app\{#MyAppIcoName}"; \ Filename: "{app}\runtime\jre\bin\{#MyAppExeName}"; \ Parameters: " -jar {#MyJarName}"; \ WorkingDir: "{app}\app\"; \ Tasks: desktopicon Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; \ IconFilename: "{app}\app\{#MyAppIcoName}"; \ Filename: "{app}\runtime\jre\bin\{#MyAppExeName}"; \ Parameters: " -jar {#MyJarName}"; \ WorkingDir: "{app}\app\"; \ Tasks: quicklaunchicon #else ; set up icons without bundled JRE Name: "{commonprograms}\{#MyAppName}"; \ IconFilename: "{app}\app\{#MyAppIcoName}"; \ Filename: "{app}\app\{#MyJarName}"; \ WorkingDir: "{app}\app\" Name: "{commondesktop}\{#MyAppName}"; \ IconFilename: "{app}\app\{#MyAppIcoName}"; \ Filename: "{app}\app\{#MyJarName}"; \ WorkingDir: "{app}\app\"; \ Tasks: desktopicon Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; \ IconFilename: "{app}\app\{#MyAppIcoName}"; \ Filename: "{app}\app\{#MyJarName}"; \ WorkingDir: "{app}\app\"; \ Tasks: quicklaunchicon #endif [Run] #if MyJREPath != "" ; run app with bundled JRE Filename: "{app}\runtime\jre\bin\{#MyAppExeName}"; Parameters: " -jar {#MyJarName}"; \ WorkingDir: "{app}\app\"; \ Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; \ Flags: postinstall skipifsilent #else ; run app without bundled JRE Filename: "{app}\app\{#MyJarName}"; \ WorkingDir: "{app}\app\"; \ Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; \ Flags: shellexec postinstall skipifsilent #endif
Hope this helps.