keishoseiho.com

Java Study Room

February 12, 2024 | by keishoseiho.com

Screenshot 2024-11-07 122547

Pseudo login-signup Java toy

I built a jar package and converted it to .exe, with jdk21(a watered-down version I deleted some parts), “CRUD” without database access. As jdk21 doesn’t separate the JRE file, the supporting jdk21 file is too big(about 180MB) to put in GitHub(limit 100MB). My file size is 210MB.

Is it really “Write once, run anywhere” ?

JRE file extracting

I tried to use jlink to separate the jre file(~80MB) from jdk21, but the jre file does not support my exe file.
use Windows PowerShell or Command Prompt get jre file: * Run as Administrator is necessary or Error

cd “C:\Program Files\Java\jdk-21”
bin\jlink.exe –module-path jmods –add-modules java.desktop –output jre

Before & After

Each JDK Release comes with its class file version. Class files are backward compatible. But class files compiled for newer JDK releases cannot be executed and will result in an UnsupportedClassVersionError.

The table lists class file versions for each JDK release. Follow the linked JDK information to find download options for a suitable JDK.

The latest version JRE I can find is Java 8, which supports class file version ~52, but can’t support a higher version, that’s why I extracted the JRE file from JDK21(Java21). I wanted a support file for my JavaFX jar file, but I didn’t find the way.

I gave up compression of the size and put a big part of JDK21 to support my exe (converted from JavaFX jar) file.

2024/08/01

Modularization was hard when I use an external library…

I improved the way to extract the necessary file for running javafx, the size of the total was reduced to 190 MB (20MB cut). I examined the necessary external library jar file and a bin file which I combined with the other bin file extracted by jlink.

I arranged the 4 jar file on the module path (in the mods file), and compiled/modularization my main source file to the same module path.

Then, I extracted Knight(=jre) for the main module, but the bin of JavaFX comes from an external library and this should be combine with the Knight file.

jlink -p mods --add-modules mian --output Knight

RELATED POSTS

View all

view all