# GraalVM Native Image CLI Options ## Classpath and modules **If native-image can't find your classes:** ```bash native-image -cp : ``` **If using modules:** ```bash native-image -p --add-modules ``` ## Build failures **If a class fails because it initializes at build time but must not:** ```bash native-image --initialize-at-run-time=com.example.LazyClass ``` **If a class must be initialized at build time:** ```bash native-image --initialize-at-build-time=com.example.EagerClass ``` **If a type must be fully defined at build time:** ```bash native-image --link-at-build-time ``` **If the build runs out of memory:** ```bash native-image -J-Xmx8g ``` **If you need to set a system property at build time:** ```bash native-image -Dkey=value ``` **If you need to pass a flag to the JVM running the builder:** ```bash native-image -J ``` ## Missing reachability metadata **If you want exact error reporting for missing reflection/JNI/proxy/resource/serialization registrations (GraalVM JDK 23+):** ```bash native-image --exact-reachability-metadata ``` **If you want to scope exact metadata handling to specific classpath entries:** ```bash native-image --exact-reachability-metadata-path= ``` ## Output and binary type **If you want to rename the output binary:** ```bash native-image -o myapp ``` **If you want to build a shared library:** ```bash native-image --shared ``` **If you want a fully statically linked binary:** ```bash native-image --static --libc=musl ``` **If you want static linking but keep libc dynamic:** ```bash native-image --static-nolibc ``` ## Performance and optimization **If you want fastest build time (dev iteration):** ```bash native-image -Ob ``` **If you want best runtime performance:** ```bash native-image -O3 ``` **If you want to optimize for binary size:** ```bash native-image -Os ``` **If you want to change the garbage collector:** ```bash native-image --gc=epsilon # no GC (throughput) native-image --gc=serial # default ``` **If you want to target the current machine's CPU features:** ```bash native-image -march=native ``` **If you need maximum compatibility across machines:** ```bash native-image -march=compatibility ``` **If you want to limit build parallelism:** ```bash native-image --parallelism=4 ``` ## Debugging and diagnostics **If you want debug symbols in the binary:** ```bash native-image -g ``` **If you want verbose build output:** ```bash native-image --verbose ``` **If you want to inspect class initialization and substitutions:** ```bash native-image --diagnostics-mode ``` **If you want a detailed HTML build report:** ```bash native-image --emit build-report # or: --emit build-report=report.html ``` **If you want to trace instantiation of a specific class:** ```bash native-image --trace-object-instantiation=com.example.MyClass ``` ## Network support **If the binary needs JDK URL protocol handlers such as HTTP or HTTPS:** ```json { "reflection": [ { "type": "sun.net.www.protocol.http.Handler", "methods": [{"name": "", "parameterTypes": []}] }, { "type": "sun.net.www.protocol.https.Handler", "methods": [{"name": "", "parameterTypes": []}] } ] } ``` The `--enable-http`, `--enable-https`, and `--enable-url-protocols` options are deprecated. Use reachability metadata instead. ## Monitoring and observability **If you need runtime monitoring (heap dumps, JFR, thread dumps):** ```bash native-image --enable-monitoring=heapdump,jfr,threaddump ``` ## Security and compliance **If you need all security services (e.g. TLS/SSL):** ```bash native-image --enable-all-security-services ``` ## Cross-compilation and platform **If you need to cross-compile for a different OS/arch:** ```bash native-image --target=linux-aarch64 ``` **If you need a custom C compiler:** ```bash native-image --native-compiler-path=/usr/bin/gcc ``` ## Info and discovery **If you want to list available CPU features:** ```bash native-image --list-cpu-features ``` **If you want to list observable modules:** ```bash native-image --list-modules ``` **If you want to see the native toolchain and build settings:** ```bash native-image --native-image-info ```