Skip to content

Latest commit

 

History

History
52 lines (36 loc) · 2.25 KB

win-jdk-portable.md

File metadata and controls

52 lines (36 loc) · 2.25 KB

How to Run Executable JAR Files with a Portable JDK on Windows

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.


🔍 Step 1: Locate Your Java Executable

Before starting, verify the exact location of your portable Java binaries.

  1. Open Command Prompt.
  2. Run the following command:
    where java
  3. Look for the bin folder path. For this guide, we assume your path is: C:\Programs\Sdk\Openjdk\bin\

💡 Note: We will use javaw.exe instead of java.exe. The javaw.exe file runs graphical (Swing/JavaFX) applications cleanly without opening an extra, empty black command prompt window.


🖱️ Method 1: The Windows "Open With" Menu

This is the easiest method to associate the file type through the Windows user interface.

  1. Right-click any .jar file on your computer.
  2. Hover over Open with and select Choose another app.
  3. Check the box that says "Always use this app to open .jar files".
  4. Scroll down and click Choose an app on your PC (or More apps -> Look for another app on this PC).
  5. Navigate to your portable JDK folder: C:\Programs\Sdk\Openjdk\bin\
  6. Select javaw.exe and click Open.

⚡ Method 2: The Administrator Command Fix (Recommended)

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.

  1. Click the Windows Start menu, type cmd, right-click Command Prompt, and select Run as administrator.
  2. Run the following command to register the .jar extension:
    assoc .jar=JarFile
  3. 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.