When using a portable OpenJDK installation (like one extracted to C:\Programs\Sdk\Openjdk\), Windows does not automatically know how to run executable .jar files when you double-click them.
This guide teaches you how to link your .jar files to your portable JDK so Swing and graphical Java applications launch instantly on a double-click.
Before starting, verify the exact location of your portable Java binaries.
- Open Command Prompt.
- Run the following command:
where java - Look for the
binfolder path. For this guide, we assume your path is:C:\Programs\Sdk\Openjdk\bin\
💡 Note: We will use
javaw.exeinstead ofjava.exe. Thejavaw.exefile runs graphical (Swing/JavaFX) applications cleanly without opening an extra, empty black command prompt window.
This is the easiest method to associate the file type through the Windows user interface.
- Right-click any
.jarfile on your computer. - Hover over Open with and select Choose another app.
- Check the box that says "Always use this app to open .jar files".
- Scroll down and click Choose an app on your PC (or More apps -> Look for another app on this PC).
- Navigate to your portable JDK folder:
C:\Programs\Sdk\Openjdk\bin\ - Select
javaw.exeand click Open.
Portable JDKs do not register themselves in the Windows Registry. If Method 1 fails, or if your JAR file flashes a window and closes immediately, you must force Windows to pass the -jar argument using the Command Prompt.
- Click the Windows Start menu, type cmd, right-click Command Prompt, and select Run as administrator.
- Run the following command to register the
.jarextension:assoc .jar=JarFile - Run this command to tell Windows exactly how to launch that file type (ensure the path matches your portable folder):
ftype JarFile="C:\Programs\Sdk\Openjdk\bin\javaw.exe" -jar "%1" %*
Your Swing JAR applications will now open seamlessly whenever you double-click them.