Hammock MicroProfile (CDI + JAX-RS + JSON) HelloWorld using Java Module System (JPMS).
The stack uses Weld 3 for CDI, RestEasy 3.5 for JAX-RS and Johnzon 1.1 for JSON
The total size of this example application is around 12mb
and the full Docker image is only 55mb
!
Note: Tested with JDK 11-ea+23
mvn clean package
mvn clean package -Pweld,docker
mvn clean package -Powb
java --module-path target/modules --module hammock.jpms
- Run jlink to create minimal JRE
jlink \
--add-modules java.logging,java.xml,java.naming,java.management,jdk.unsupported \
--verbose \
--strip-debug \
--compress 2 \
--no-header-files \
--no-man-pages \
--output target/jlink-image
- Run minimal JRE with patch module for
java.beans
:
target/jlink-image/bin/java \
--patch-module java.base=target/patch/java.beans \
--add-exports java.base/java.beans=johnzon.mapper \
--add-exports java.base/java.beans=org.apache.logging.log4j.core \
--module-path target/modules \
--module hammock.jpms
Note: https://github.com/panga/lite-beans was used to patch java.beans
implementation required by some 3rd party dependencies and remove the requirement of adding java.desktop
module into the minimal JRE.
docker run --rm -it -p 8080:8080 hammock-jpms
curl http://localhost:8080/hello