Search code examples
javaxmllaunch4j

How to get Launch4j XML Config to Bundle JRE Properly?


I have a program I'd really like to utilize a dedicated JRE rather than require my clients to download Java. I'm using Launch4j as my build tool, and have been attempting to use the bundled JRE feature. I've copied the JRE into my program's directory, and is set up as follows:

//home/user/Program Name:

/cfg (contains Launch 4j xml build file)
/bin (contains signature key, exe, and Jar file)
/Runtime (contains working copy of JRE)

I have tried modifying the xml to point directly to the Javaw.exe in the JRE, but that didn't make a difference. I've also tried adding the following line to the xml per other SO forums, but honestly I'm not 100% sure what it does:

<opt>-DgvSIG.confDir=../cfg</opt>

My question is what modifications do I need to make to my xml config so that any remote user can open my program without 1st downloading Java. I am on Windows, and getting this working just for windows is fine for now. Here is my xml:

<launch4jConfig>
  <dontWrapJar>false</dontWrapJar>
  <headerType>console</headerType>
  <jar>C:\Users\zrr81\Climate Dev Pegasus\bin\ClimateDevPegasus_Alpha.jar</jar>
  <outfile>C:\Users\zrr81\Climate Dev Pegasus\bin\ClimateDevPegasus_Alpha.exe</outfile>
  <errTitle></errTitle>
  <cmdLine></cmdLine>
  <chdir>.</chdir>
  <priority>normal</priority>
  <downloadUrl>http://java.com/download</downloadUrl>
  <supportUrl></supportUrl>
  <stayAlive>false</stayAlive>
  <restartOnCrash>false</restartOnCrash>
  <manifest></manifest>
  <icon>C:\Users\zrr81\Climate Dev Pegasus\Pegasus.ico</icon>
  <jre>
    <path>Climate Dev Pegasus\Runtime\jdk-13.0.1\bin\javaw.exe</path>
    <bundledJre64Bit>true</bundledJre64Bit>
    <bundledJreAsFallback>false</bundledJreAsFallback>
    <minVersion>1.5.0</minVersion>
    <maxVersion>13.0.2</maxVersion>
    <jdkPreference>preferJre</jdkPreference>
    <runtimeBits>64/32</runtimeBits>
  </jre>
</launch4jConfig>

Solution

  • So turns out this is fairly simple to fix, but very hard to find proper information on. There is a setting in Launch 4J that lets you force a local JDK and prevent the program from trying to force a fresh install:

    enter image description here

    When you push that setting, it will allow you to use the bundled JRE and generate the following line in the XML:

    <jdkPreference>jdkOnly</jdkPreference>