Correspondence when Java application exed by launch4j does not work on windows with openJDK installed

I'm using various OpenJDK distributions because I'm not sure if I have an Oracle-Java license. Because of my work, I sometimes make client-type apps, so I made it in Java because it can support Mac / Win (relatively easily). If the jar file is left as it is, some people may not be able to use it due to the problem of association, so it is very difficult to exe, so I wrapped it in exe with launch4j, It turns out that it doesn't start with certain OpenJDK. The following is the remedy. (In addition, since there is a part to edit the registry, we can not take responsibility for troubles as usual)

OpenJDK distribution that can be started with lanunch4j

・ Amazon Coretto ・ AdoptOpenJDK

However, Amazon Coretto uses Liberica OpenJDK because JavaFX media support has not been implemented yet, and Adopt does not have JavaFX. This Liberica can't run launch4j. (I haven't tried it, but zuru OpenJDK seems to be useless)

With Liberica installed

-JAVA_HOME is set. -Since it is also added to PATH, the java command can be used from the command prompt etc. -However, launch4j cannot be started because it is said that there is no JDK.

From the official Oracle JDK documentation

https://docs.oracle.com/javase/jp/9/install/installation-jdk-and-jre-microsoft-windows-platforms.htm#JSJIG-GUID-47C269A3-5220-412F-9E31-4B8C37A82BFB The normal JDK installer writes the Windows registry key. Since launch4j is a method of reading and judging the above registry key, it does not work because the registry key is not written depending on the OpenJDK distribution.

Add registry key

** Promise: Make a backup just in case before changing the registry. ** ** After trying various things, I was able to start it by adding this key. HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.8 So, additional commands (from the command prompt in admin mode)

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment" /v CurrentVersion /t REG_SZ /d "1.8.0_252"
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.8" /v JavaHome /t REG_SZ /d "%JAVA_HOME%\jre"

Rewrite "1.8.0_252" on the first line to the Java version as appropriate. Also, match the "1.8" part of the path to the version in the same way.

(Maybe this is also) reg add "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.8.0_252"

Digression

If the jar doesn't launch with a double click, HKEY_CLASSES_ROOT¥.jar Sometimes it works if you remove the registry key and reinstall JRE.

Referenced URL

https://sourceforge.net/p/launch4j/feature-requests/103/ https://github.com/AdoptOpenJDK/openjdk-installer/issues/64

Recommended Posts

Correspondence when Java application exed by launch4j does not work on windows with openJDK installed
[Kotlin] The mapping library by reflection based on Java basically does not work with Kotlin.
Install Java with zip on Windows
Using JupyterLab + Java with WSL on Windows 10
Memory measurement of Java application on Windows
Install Java 11 (OpenJDK: AdoptOpenJDK) on macOS with Homebrew
Install Java 14 (OpenJDK: AdoptOpenJDK) on macOS with Homebrew
When @Transactional of Spring Boot does not work
Install Java 8 (OpenJDK: AdoptOpenJDK) on macOS with Homebrew
Eclipse does not start after Java 11 is installed
[Solution] Java cannot be installed on Windows 10 + ATOK 2017