Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 1.97 KB

README-native-image.md

File metadata and controls

56 lines (42 loc) · 1.97 KB

How to build a native image

Reference: https://www.graalvm.org/22.1/reference-manual/native-image/Resources/

By default, the native-image tool will not integrate any of the resources that are on the classpath into the native executable. To make calls such as Class.getResource() or Class.getResourceAsStream() (or their corresponding ClassLoader methods) return specific resources (instead of null), you must specify the resources that should be accessible at runtime. This can be achieved using a configuration files generated by the following process.

1 Install latest version of GraalVM from Release page

export environment variables

VMDIR=/Library/Java/JavaVirtualMachines
GRDIR=graalvm-ce-java17-22.2.0
sudo xattr -r -d com.apple.quarantine $VMDIR/$GRDIR
export GRAALVM_HOME=$VMDIR/$GRDIR/Contents/Home
jenv add $GRAALVM_HOME
export PATH=$GRAALVM_HOME/bin:$PATH

install native-image binary

gu install native-image

2 Build fat jar and generate the configuration

No need to run again, unless there was a change in dependencies in build.gradle Run all commands, so that the generated configuration is as much as complete

./gradlew assemble

VERSION=3.4.5

java -agentlib:native-image-agent=config-merge-dir=./src/main/resources/META-INF/native-image \
	-jar build/libs/msastarter-$VERSION-all.jar
java -agentlib:native-image-agent=config-merge-dir=./src/main/resources/META-INF/native-image \
	-jar build/libs/msastarter-$VERSION-all.jar generate --useDefault
java -agentlib:native-image-agent=config-merge-dir=./src/main/resources/META-INF/native-image \
	-jar build/libs/msastarter-$VERSION-all.jar publish --useDefault

3 Build native image

./gradlew nativeCompile -DgraalvmNative.agent.enabled=true
# Finished generating 'msastarter' in 27.5s.
#    [native-image-plugin] Native Image written to: {PROJECT_DIR}/build/native/nativeCompile
# BUILD SUCCESSFUL in 29s