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-11-jdk package from Ubuntu 18.04 and newer – they require GLIBC v2.27. 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-11-jdk package in Ubuntu 16.04 (which is still based on “old enough” GLIBC v2.23).

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.compiler,java.desktop,java.management,java.naming,java.sql,jdk.xml.dom

The reported dependencies can be explained as follows:

Another dependency reported on one-by-one analysis of lib/*jar libraries (affected functionality is probably not used in Workcraft):

Create minimal JRE with specific modules as follows:

jlink --output jre --strip-debug --no-man-pages --no-header-files --compress=2 \
--add-modules java.base,java.compiler,java.desktop,java.management,java.naming,java.sql,jdk.xml.dom,java.logging

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. In some cases it helped to reduce JRE size from 450M to 45M:

strip --preserve-dates --strip-unneeded jre/lib/*.so jre/lib/server/*.so jre/bin/java jre/bin/keytool