Justin Reeves
Justin Reeves

Reputation: 1188

launch4j exe can't find jre

Issues with launch4j

Program consists on one uber jar via maven-shade plugin and a Data/ Runs fine on any jre7 machine, windows or linux

However I've been unable to get launch4j to work.

launch4j config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<launch4jConfig>
  <dontWrapJar>false</dontWrapJar>
  <headerType>gui</headerType>
  <jar>pllsolver-0.2alpha.jar</jar>
  <outfile>pllsolver-0.2alpha.exe</outfile>
  <errTitle>NO JRE FOUND</errTitle>
  <cmdLine></cmdLine>
  <chdir></chdir>
  <priority>normal</priority>
  <downloadUrl>http://java.com/download</downloadUrl>
  <supportUrl></supportUrl>
  <stayAlive>false</stayAlive>
  <manifest></manifest>
  <icon>sicr.ico</icon>
  <jre>
    <path>jre7</path>
    <bundledJre64Bit>false</bundledJre64Bit>
    <minVersion></minVersion>
    <maxVersion></maxVersion>
    <jdkPreference>preferJre</jdkPreference>
    <runtimeBits>64/32</runtimeBits>
  </jre>
  <splash>
    <file>sicr.bmp</file>
    <waitForWindow>false</waitForWindow>
    <timeout>5</timeout>
    <timeoutErr>true</timeoutErr>
  </splash>
  <messages>
  </messages>
</launch4jConfig>

Then to build, on windows, I try this:

PS K:\test> set PATH="K:\test\jre7\bin\"
PS K:\test> ..\launch4j\launch4jc.exe .\config.xml
launch4j: Compiling resources
launch4j: Linking
launch4j: Wrapping
launch4j: Successfully created K:\test\.\pllsolver-0.2alpha.exe
PS K:\test> .\pllsolver-0.2alpha.exe
PS K:\test>

It's at this point that I get a nice little window about how it failed to find the JRE.

Java is in K:\test\jre7\bin\java.exe My jar is K:\test\pllsolver-0.2alpha.jar

Additionally, I don't know if this will be an issue yet, but the executable and the Data/ need to be in the same directory. I'm planning to do better pathing later but I don't have a clear understanding of Windows ENV variables.

Upvotes: 2

Views: 9627

Answers (4)

Joe
Joe

Reputation: 83

This fixed it for me. The %PATH% was missing

<jre>
    <path>%JAVA_HOME%;%PATH%</path>
    <requiresJdk>false</requiresJdk>
    <requires64Bit>false</requires64Bit>
    <minVersion></minVersion>
    <maxVersion></maxVersion>
  </jre>

Upvotes: 1

Christian Benner
Christian Benner

Reputation: 104

It appears to be that launch4j is looking for the JRE path relative to its 'outfile' location.

Solutions:

  • You can use an absolute path e.g. 'C:\loc\of\jre'
  • Put your JRE in your 'outfile' directory and set the JRE path relatively e.g. 'jre'
  • Treat the JRE path as relative to the 'outfile' directory e.g. '....\somefolder\jre'

My launch4j version: 3.14

Upvotes: 0

Pulsar07
Pulsar07

Reputation: 81

I struggled around with the JRE setting using launch4j 3.12 (2020) and OpenJDK and got also the message "no java runtime found". My target, was to use OpenJDK (https://adoptopenjdk.net/) Two ways were successful:

  1. Install OpenJDK, with the JavaSoft (Oracle) registry keys activated and select the "only use public JREs" launch4j-option.
  2. Install OpenJDK, with the JAVA_HOME option set, and set the "bundled jre path" in the JRE tab to %JAVA_HOME% (xml content: %JAVA_HOME%) With this you are able to use different JRE for different applications setting the JAVA_HOME variable for each of the differently.

Upvotes: 3

matthiasboesinger
matthiasboesinger

Reputation: 458

a bit late but maybe it can still help you ...

One thing which works for sure with launch4j and JRE is to bundle the JRE in the folder of your application.

To do so:

  • create a path 'jre' in the folder with your '*.exe'
  • copy a JRE in this folder (this jre has to fit the 'min'/'max' conditions you have set)
  • set '<path>/jre</path>' inside the <jre> configuration of your '.xml'

... this should work

Upvotes: 3

Related Questions