# Builds a self-contained native app-image (bundled JRE, no Java required on target). # Requires a JDK 17+ on PATH (needs jar, jdeps, jpackage). Tested with Temurin 21. # Reuses the ORIGINAL compiled .class files from the shipped exe (identical behavior). # # Usage: powershell -ExecutionPolicy Bypass -File build-app-image.ps1 $ErrorActionPreference = "Stop" $root = $PSScriptRoot $work = Join-Path $root "build-tmp" $classes = Join-Path $work "classes" $dist = Join-Path $root "dist" Remove-Item $work, $dist -Recurse -Force -ErrorAction SilentlyContinue New-Item -ItemType Directory -Force $classes | Out-Null # 1. Extract the class files (the .exe is a launcher stub + a ZIP/JAR). Copy-Item (Join-Path $root "VncThumbnailViewerWin1.4.2.exe") (Join-Path $work "app.zip") Expand-Archive -Path (Join-Path $work "app.zip") -DestinationPath $classes -Force # 2. Repackage into a runnable JAR, preserving the original manifest (Main-Class). $jar = Join-Path $work "VncThumbnailViewer.jar" $jarInput = Join-Path $work "jarinput" New-Item -ItemType Directory -Force $jarInput | Out-Null & jar --create --file $jar --manifest (Join-Path $classes "META-INF\MANIFEST.MF") -C $classes . # 3. Determine the minimal module set for a slim runtime. $mods = (& jdeps --multi-release 21 --ignore-missing-deps --print-module-deps $jar).Trim() Write-Host "Modules: $mods" # 4. Build the native app-image with a jlinked, bundled runtime. Move-Item $jar $jarInput & jpackage --type app-image ` --name "VncThumbnailViewer" --app-version "1.4.2" --vendor "DJC" ` --input $jarInput --main-jar "VncThumbnailViewer.jar" --main-class "VncThumbnailViewer" ` --add-modules $mods --dest $dist Remove-Item $work -Recurse -Force -ErrorAction SilentlyContinue Write-Host "Done -> $dist\VncThumbnailViewer\VncThumbnailViewer.exe"