Search code examples
javajarexe

How do I make my java program use my custom JRE when executed by double-clicking, rather than the default JDK installed?


As you probably know, since JDK 9, JRE no longer exists. So you need to create your own custom JRE with jlink. Well, so did I. And then I converted the jar to exe using launch4j. However, when I double-click it, it uses the JDK located at C:\Program File\Java\jdk-16.0.1 rather than the JRE I created. How do I make the exe use my JRE instead of the default JDK?

Thanks! Regards,

Fida


Solution

  • If you want to use your jre used by applications then you have to set the path in your OS. But this will make all application to use your jre.

    JAVA_HOME = C:\somepath\yourjre
    

    You also have to update path variable with bin folder.

    PATH = C:\somepath\yourjre\bin