Architecture & Technical Implementation
This project is a zero-dependency, lightweight, native Windows implementation designed to bypass the traditional complexities of virtualized bash scripts (like SDKMAN!) on Windows operating systems.
The Core Mechanism: Directory Junctions
Instead of constantly appending and pruning your Windows PATH variable to point to different JDK folders (which quickly leads to the 1024-character PATH limit and environment variable bloat), the manager maintains a single Directory Junction (mklink /J) at:
%LOCALAPPDATA%\DiamTek\JVM\current
Your system PATH only ever needs to contain %LOCALAPPDATA%\DiamTek\JVM\current\bin. When you switch Java versions, the manager simply tears down the old junction and repoints it to the target JDK directory. This provides O(1) symlink resolution for the OS.
Dual-Architecture Core (Symlink Mode vs. Legacy Registry Mode)
The engine provides two distinct switching engines that users can toggle via the Settings menu or CLI flags:
- Symlink Mode (Default, UAC-Free):
- Mechanism: Updates the NTFS Directory Junction pointer (
%LOCALAPPDATA%\DiamTek\JVM\current) in user-space. - Privileges: Standard user space (100% UAC-free, zero admin popups).
- Compatibility: Native for 99% of modern tools (Maven, Gradle, IntelliJ IDEA, VS Code, Eclipse).
- Mechanism: Updates the NTFS Directory Junction pointer (
- Registry Mode (Legacy, UAC Required):
- Mechanism: Directly writes the absolute JDK path to the Machine-level Windows Registry (
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment) and updates the system-wide MachinePATH. - Privileges: Requires Administrator (UAC) Elevation on every switch, spawning an elevated background PowerShell worker via
Start-Process -Verb RunAs. - Compatibility: 100% unbreakable fallback for legacy enterprise applications, obscure Windows service runners, or ancient classloaders that perform strict canonical path checks and cannot resolve NTFS Directory Junctions.
- Mechanism: Directly writes the absolute JDK path to the Machine-level Windows Registry (
Deep OS Environment Management
To ensure deep OS integration without requiring users to download external binaries (like setx augmentations), the tool relies on inline PowerShell execution invoked seamlessly via cmd.exe.
Global/Machine State (HKLM)
- Updates to the global
PATHandJAVA_HOMEare performed natively using the .NET framework bridging in PowerShell:[Environment]::SetEnvironmentVariable('JAVA_HOME', $target, 'Machine') - The script detects if it is running in standard user space. If required, it dynamically generates an elevated PowerShell script (
jvm_elevate_XXXX.ps1) in%TEMP%and executes it viaStart-Process -Verb RunAs.
Session State Isolation
- Updating the Windows Registry does not update the live, running terminal session. To solve this, the script dynamically evaluates the environment block within the execution boundary.
- Dynamic Filtering: Instead of using batch string substitution (
!PATH:string=!), which is vulnerable to quote-collisions and delayed expansion parsing bugs, the manager pipes the variable manipulation to PowerShell using the-notoperator against$env:PATH. This guarantees 100% accurate string evaluation and prevents the accidental deletion of unrelated paths (e.g., pruningJAVA_HOME_Backupwhile searching forJAVA_HOME).
Ecosystem Routing (Universal Candidate Engine)
Like SDKMAN!, this tool intercepts commands for popular Java tools (Maven, Gradle, Kotlin, Scala, Groovy). The CLI acts as a universal router:
- It intercepts the
jvm install <candidate> <version>command. - It executes a PowerShell
Invoke-RestMethodto the respective API (Adoptium, GitHub Releases, Azul, etc.) to securely resolve the download URL and SHA-256 checksums. - The payloads are extracted via
Expand-Archiveand isolated in%LOCALAPPDATA%\DiamTek\JVM\candidates\<candidate>. - Specific
<CANDIDATE>_HOMEvariables are injected into the registry, mapping the ecosystem completely identically to native Java.
Real-Time PowerShell Session Propagation (Set-JvmVar)
Because Windows process environments cannot ordinarily be modified by a child batch process, install.ps1 injects a native PowerShell function hook into $PROFILE.
When jvm switches an active tool or JDK:
jvm.batwrites target environment pairs (KEY=VALUE) to$env:TEMP\.jvm_session_target.- The PowerShell wrapper intercepts the return code and invokes
Set-JvmVar. Set-JvmVarsurgically strips the old\bindirectory from$env:Pathand prepends the new\bindirectory directly into the current PowerShell process memory.- It updates
$env:JAVA_HOME(or corresponding tool variables) live, providing instantaneous switching without reopening terminal tabs.
Bulletproof Batch Heredoc Escaping
Windows cmd.exe does not natively support Bash-style heredocs (cat <<EOF). Embedding multi-line PowerShell scripts inside a batch ( ... ) > script.ps1 redirection block requires careful escaping:
- Redirection operators (
<,>) are escaped as^<,^>. - Pipes (
|) and command separators (&) are escaped as^|,^&. - Parentheses (
(,)) are escaped as^(,^)to prevent premature termination of the enclosing batch block. - Exclamation marks (
!) are escaped as^^!to prevent corruption by CMD’s delayed variable expansion engine (setlocal enabledelayedexpansion).
Deep Uninstaller & Windows Integration Architecture
The uninstaller subsystem (uninstall.ps1) is designed for 100% total system sanitization:
- UAC Escalation: Uses .NET security principals to check for elevated tokens; if missing, automatically spawns an elevated PowerShell host via
Start-Process -Verb RunAs. - Registry Integration: Registers under
HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\DiamTek.JVMwith native Windows “Installed apps” metadata, dynamicEstimatedSizecomputation (with a 1,024 KB floor for Windows 11 compatibility), and creates a Start Menu uninstaller shortcut inStart Menu\Programs\DiamTek. - Dual-Scope Cleanup: Cleans both
UserandMachineenvironment variables andPATHregistries, surgically strips the$PROFILEhook, deletes the AppData Ecosystem cache, purges Windows Terminal profiles, removes pinned taskbar shortcuts, cleans session files, and prompts to cleanC:\Program Files\Java.
Windows Terminal & Shell Integration Architecture
To provide a first-class modern Windows developer experience while strictly maintaining 100% pure Batch & PowerShell code:
- Dynamic Profile Injection:
install.ps1scans for Windows Terminal configurations across Release, Preview, and Unpackaged locations (LocalState\settings.json). It injects a dedicated profile with GUID{b20650a4-4212-4d64-9edf-744e9285e2be}, pointing to high-resolutionassets/icon.png. - Tab Lifecycle Management: Configured with
cmd.exe /candcloseOnExit: always. When a developer exits the interactive JVM menu (exit /B 0), the hostingcmd.exeprocess terminates, signaling Windows Terminal to immediately close the tab. - Shortcut Synchronization: Creates Start Menu application shortcuts targeting
wt.exe -p "Java Version Manager"(falling back tocmd.exe /con systems without Windows Terminal). During installation and self-updates, the script automatically searches%APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\to detect and update existing pinned taskbar shortcuts in place. - AppUserModelID & Taskbar Mechanics: Windows Terminal is a packaged WinUI app that hardcodes its own process-level AppUserModelID (
Microsoft.WindowsTerminal...) on all hosting windows. By registering a dedicated profile with native icon and dropdown integration rather than forcing brittle binary wrappers, the utility respects the OS container model while maintaining a zero-binary, 100% script-based repository.
Multi-Channel Packaging Pipelines
- Winget: Native YAML manifest (
packages\winget\DiamTek.JVM.yaml) declaring installer metadata and portable packaging. - Scoop: JSON manifest (
packages\scoop\jvm.json) that automates downloading and bootstrapsinstall.ps1. - Chocolatey: Package specification (
packages\choco\jvm.nuspec) with automatedchocolateyInstall.ps1andchocolateyUninstall.ps1scripts. - WiX Toolset v4 (MSI): Automated build script (
packages\msi\build-msi.ps1) that compiles a native, per-user Windows Installer (.msi) bundlingjvm.bat,uninstall.ps1,LICENSE, andREADME.md.