'Launch4J not recognizing Eclipse Temurin OpenJDK Java 17
I'm using Windows 10 and I have Java 17 installed, with JAVA_HOME set correctly. java --version gives this:
openjdk 17.0.2 2022-01-18
OpenJDK Runtime Environment Temurin-17.0.2+8 (build 17.0.2+8)
OpenJDK 64-Bit Server VM Temurin-17.0.2+8 (build 17.0.2+8, mixed mode, sharing)
In a Maven parent POM I have Launch4j via the launch4j-maven-plugin 2.1.1 configured to generate an EXE using my current JRE:
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<id>generate-exe</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
...
<jre>
<minVersion>${maven.compiler.release}</minVersion>
</jre>
...
This parent POM also specifies Java 8 (although it requires Java 9+ to build):
<properties>
<maven.compiler.release>8</maven.compiler.release>
...
My CLI project POM uses the parent POM above. I build the Maven project with no problem, and it generates my-cli.exe. I can run my-cli.exe just fine.
But I want to use Java 17 in the My CLI, which should be fine since I have Java 17 installed. So I set the following in the My ClI project:
<properties>
<maven.compiler.release>17</maven.compiler.release>
...
I clean and rebuild the project, and it outputs my-cli.exe just as before. But when I try to run my-cli.exe, it prints:
My CLI: This application requires a Java Runtime Environment 17
Then it opens my browser to https://java.com/en/download/.
From Launch4J Bug 197, it appears that Launch4J doesn't look at the JAVA_HOME environment variable, but instead looks at the Windows registry. That means it ignores any manually-installed JDKs. 😞 So I went to Adoptium and used the installer to install the latest release, OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.msi. In my Windows installed programs, it shows "Eclipse Temurin JDK with Hotspot 17.0.2+8 (x64). Unfortunately the same thing happens; Launch4J still doesn't recognize it.
Why is Launch4J not recognizing that OpenJDK 17.0.2+8 is a "Java Runtime Environment 17"?
Solution 1:[1]
Apparently as per Launch4J Bug Feature Request 103, Launch4J doesn't look at the same registry keys that OpenJDK uses, and only works with Oracle JDK registry keys. There's an Adoptium Issue 64 which requests that Adoptium use the same registry keys as Oracle, but it looks like this was abandoned because of gotchas.
As noted in the feature request above, Launch4J should be looking at the JAVA_HOME environment anyway.
It looks like Launch4J won't work with OpenJDK, which makes it basically worthless in today's world. What a disappointment.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Garret Wilson |
