Run a JAR file using a specific JRE

A JRE directory has a bin/java.exe.

You can run a jar from that JRE simply with

<path_to_jre>/bin/java.exe -jar Executable.jar

If you don't want to have to open a console each time, simply put the above line in a .bat file and double click on that.


Run from command

<path_to_jre>/bin/java.exe -jar Executable.jar

(or use javaw.exe to return to command prompt immediately after launch of the JAR)

Or set environment variables

Many start scripts respect variables JRE_HOME and JAVA_HOME for JRE and JDK respectively. Some don't like spaces, so use short path convention (C:\Progra~1\Java\jre1.8.0_171)

On 64bit systems:
Progra~1 = Program Files
Progra~2 = Program Files (x86)

Or set file associations

to launch JARs by double clicking. Unfortunately, the GUI (Control Panel\All Control Panel Items\Default Programs\Set Associations) is quite lousy, so you have to do it in Registry.

This is my favorite method to choose 32/64bit JRE, when the Control Panel setting is ignored.

  1. Check that the default value in HKEY_CLASSES_ROOT\.jar is jarfile
  2. Check that the default value in HKEY_CLASSES_ROOT\jarfile\shell\open\command points to your JRE.

In my case for 64bit env:

"C:\Program Files\Java\jre1.8.0_171\bin\javaw.exe" -jar "%1" %*

Mind the quotes: javaw path contains space; the JAR path can contain spaces; passed parameters are space separated.