Skip to content

Instantly share code, notes, and snippets.

@nik-sta
Last active July 5, 2022 06:27
Show Gist options
  • Select an option

  • Save nik-sta/21ce64680968b6b5f3bc0d5362e377a2 to your computer and use it in GitHub Desktop.

Select an option

Save nik-sta/21ce64680968b6b5f3bc0d5362e377a2 to your computer and use it in GitHub Desktop.
Production-ready Application Build Bash Script for layered Spring Boot Applications
#!/bin/sh
JAR_FILE=application.jar
if [ ! -f "$JAR_FILE" ]; then
echo "build.error: application jar is missing!"
exit 1
fi
jar xf application.jar
REQUIRED_JAVA_MODULES="$(jdeps \
--print-module-deps \
--ignore-missing-deps \
--recursive \
--multi-release 17 \
--class-path="./BOOT-INF/lib/*" \
--module-path="./BOOT-INF/lib/*" \
./application.jar)"
if [ -z "$REQUIRED_JAVA_MODULES" ]; then
echo "build.error: required java modules are not determined!"
exit 1
fi
jlink \
--no-header-files \
--no-man-pages \
--compress 2 \
--add-modules "${REQUIRED_JAVA_MODULES}" \
--output /opt/java-runtime
java -Djarmode=layertools -jar application.jar extract
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment