====== Preparing minimal Java Runtime Environment ======
Standard distribution of Java Runtime Environment (JRE) unpacks to around 125MB. This can be significantly reduced by only including those JRE components that are actually used by Workcraft. For this we use Java Development Kit (JDK), preferably the one from https://adoptium.net/, and an unpacked Workcraft distribution.
RedHat7 and CentOS 7 use GCLIB v2.17, which is incompatible with ''*.so'' files in ''openjdk-21-jdk'' package from Ubuntu 24.04 and newer -- they use GLIBC v2.39, which is not compatible with v2.17. Therefore, minimal JRE should be created either using locally installed JDK from https://adoptium.net/ (its ''*.so'' files are compatible with GLIBC v2.17), or using ''openjdk-21-jdk'' package in Ubuntu 22.04 (which is still based on "old enough" GLIBC v2.34).
Print module dependencies of all Workcraft ''bin/*.jar'' files with their dependencies located in ''lib/'':
jdeps --recursive --print-module-deps --ignore-missing-deps --multi-release base --class-path lib/* bin/*
The reported dependencies are as follows:
java.base,java.desktop,java.naming,java.sql,jdk.dynalink,jdk.xml.dom
The reported dependencies can be explained as follows:
* ''java.base'', ''java.desktop'' - core functionality
* ''java.naming'', ''java.sql'', ''jdk.dynalink'' - used in Rhino library for JavaScript support
* ''jdk.xml.dom'' - used in ''xml-apis-ext'' for SVG support
Other dependencies reported on one-by-one analysis of ''lib/*.jar'' libraries (affected functionality is probably not used in Workcraft, but safer to include these dependencies too):
* ''java.logging'' -- used in ''common-logging'' and ''javax.activation'' libraries
* ''java.xml'' -- used in ''batik-script'' and ''jbpt'' libraries
Create minimal JRE with specific modules as follows (note that ''%%--compress=2%%'' does help reducing the size, even though there is a warning that this option is deprecated):
jlink --output jre --strip-debug --no-man-pages --no-header-files --compress=2 --add-modules \
java.base,java.desktop,java.naming,java.sql,jdk.dynalink,jdk.xml.dom,java.logging,java.xml
In Linux (depending on the used JDK) some of ''*.so'' files in the produced JRE are significantly larger than expected. This is a known problem and the solution is to strip dynamic libraries and binaries of debug symbols. It helped to reduce JRE size to 55M (most of the time from ~60M, but sometimes from 450M):
strip --preserve-dates --strip-unneeded jre/lib/*.so jre/lib/server/*.so jre/bin/java jre/bin/keytool