- Latest (GraalVM for JDK 21)
- Dev Build
- GraalVM for JDK 21
- GraalVM for JDK 20
- GraalVM for JDK 17
- GraalVM 22.3
- GraalVM 22.2
- GraalVM 22.1
- GraalVM 22.0
- GraalVM 21.3
- Getting Started with Native Image
- Native Image Basics
- Build Overview
- Build Output
- Build Configuration
- Native Image Bundles
- Build Options
- Hosted and Runtime Options
- Reachability Metadata
- Optimizations and Performance
- Debugging and Diagnostics
- Dynamic Features
- Interoperability with Native Code
- LLVM Backend
- Workshops and Labs
Native Image Build Options
Depending on the GraalVM version, the options to the
native-image builder may differ.
-cp, -classpath, --class-path <class search path of directories and zip/jar files>: a
;on Windows) separated list of directories, JAR archives, and ZIP archives to search for class files
-p <module path>, --module-path <module path>: a
;on Windows) separated list of directories. Each directory is a directory of modules.
--add-modules <module name>[,<module name>...]: add root modules to resolve in addition to the initial module.
<module name>can also be
-D<name>=<value>: set a system property
-J<flag>: pass an option directly to the JVM running the
--diagnostics-mode: enable diagnostics output: class initialization, substitutions, etc.
--enable-preview: allow classes to depend on preview features of this release
--enable-native-access <module name>[,<module name>...]: enable modules that are permitted to perform restricted native operations.
<module name>can also be
--verbose: enable verbose output
--version: print the product version and exit
--help: print this help message
--help-extra: print help on non-standard options
--auto-fallback: build a standalone executable if possible
--color: color build output (
--configure-reflection-metadata: enable runtime instantiation of reflection objects for non-invoked methods
--enable-all-security-services: add all security service classes to the generated native executable
--enable-http: enable HTTP support in a native executable
--enable-https: enable HTTPS support in a native executable
--enable-monitoring: enable monitoring features that allow the VM to be inspected at run time. A comma-separated list can contain
all(deprecated behavior: defaults to
allif no argument is provided). For example:
--enable-sbom: embed a Software Bill of Materials (SBOM) in the executable or shared library for passive inspection. A comma-separated list can contain
cyclonedxif no argument is provided), or
exportto save the SBOM to the native executable’s output directory. The optional
strictflag aborts the build if any class cannot be matched to a library in the SBOM. For example:
--enable-sbom=cyclonedx,strict. (Not available in GraalVM Community Edition.)
--enable-url-protocols: list comma-separated URL protocols to enable
--features: a comma-separated list of fully qualified Feature implementation classes
--force-fallback: force building of a fallback native executable
--gc=<value>: select a Native Image garbage collector implementation. Allowed options for
G1for G1 garbage collector (not available in GraalVM Community Edition);
epsilonfor Epsilon garbage collector;
serialfor Serial garbage collector (default).
--initialize-at-build-time: a comma-separated list of packages and classes (and implicitly all of their superclasses) that are initialized during generation of a native executable. An empty string designates all packages.
--initialize-at-run-time: a comma-separated list of packages and classes (and implicitly all of their subclasses) that must be initialized at run time and not during generation. An empty string is currently not supported.
--libc: select the
libcimplementation to use. Available implementations are
--link-at-build-time: require types to be fully defined at native executable build time. If used without arguments, all classes in scope of the option are required to be fully defined.
--link-at-build-time-paths: require all types in given class or module path entries to be fully defined at native executable build time
--list-cpu-features: show CPU features specific to the target platform and exit
--list-modules: list observable modules and exit
--native-compiler-options: provide a custom C compiler option used for query code compilation
--native-compiler-path: provide a custom path to the C compiler used to query code compilation and linking
--native-image-info: show the native toolchain information and executable’s build settings
--no-fallback: build a standalone native executable or report a failure
--parallelism: specify the maximum number of threads to use concurrently during native executable generation
--pgo: provide a comma-separated list of files from which to read the data collected for Profile-guided optimization of AOT-compiled code (reads from default.iprof if nothing is specified). Each file must contain a single
PGOProfilesobject, serialized in JSON format, optionally compressed by gzip. (Not available in GraalVM Community Edition.)
--pgo-instrument: instrument AOT-compiled code to collect data for Profile-guided optimization into the default.iprof file. (Not available in GraalVM Community Edition.)
--pgo-sampling: perform profiling by sampling the AOT compiled code to collect data for Profile-guided optimization. (Not available in GraalVM Community Edition.)
--report-unsupported-elements-at-runtime: report the usage of unsupported methods and fields at run time when they are accessed the first time, instead of an error during executable’s building
--shared: build a shared library
--silent: silence build output
--static: build a statically-linked executable (requires
--strict-image-heap: enable the strict image heap mode that allows all classes to be used at build-time but also requires types of all objects in the heap to be explicitly marked for build-time initialization.
--target: select the compilation target for
<OS>-<architecture>format). It defaults to host’s OS-architecture pair.
--trace-class-initialization: provide a comma-separated list of fully-qualified class names that a class initialization is traced for
--trace-object-instantiation: provide a comma-separated list of fully-qualified class names that an object instantiation is traced for
-O<level>: control code optimizations where available variants are:
b- optimize for fastest build time,
0- no optimizations,
1- basic optimizations,
2- aggressive optimizations,
3- all optimizations for best performance (enabled automatically with the Profile-guided optimization)
disableassertions[:[packagename]|:[classname]: disable assertions with specified granularity at run time
-disablesystemassertions: disable assertions in all system classes at run time
enableassertions[:[packagename]|:[classname]: enable assertions with specified granularity at run time
-enablesystemassertions: enable assertions in all system classes at run time
-g: generate debugging information
-march: generate instructions for a specific machine type. Defaults to
x86-64-v3on AMD64 and
armv8-aon AArch64. Use
-march=compatibilityfor best compatibility, or
-march=nativefor best performance if a native executable is deployed on the same machine or on a machine with the same CPU features. To list all available machine types, use
-o: name of the output file to be generated
Macro Options #
Non-standard Options #
native-image --help-extra for non-standard options help.
--exclude-config: exclude configuration for a comma-separated pair of classpath/modulepath pattern and resource pattern. For example:
--exclude-config foo.jar,META-INF\/native-image\/.*.propertiesignores all .properties files in META-INF/native-image in all JARs named _foo.jar`-.
--expert-options: list image build options for experts
--expert-options-all: list all image build options for experts (use at your own risk). Options marked with Extra help available contain help that can be shown with
--expert-options-detail: display all available help for a comma-separated list of option names. Pass
*to show extra help for all options that contain it.
--configurations-path <search path of option-configuration directories>: a separated list of directories to be treated as option-configuration directories.
--debug-attach[=<port or host:port (* can be used as host meaning bind to all interfaces)>]: attach to a debugger during native executable generation (default port is 8000)
--diagnostics-mode: Enables logging of image-build information to a diagnostics folder.
--dry-run: output the command line that would be used for building
--bundle-create[=new-bundle.nib]: in addition to image building, create a native image bundle file (*.nibfile) that allows rebuilding of that image again at a later point. If a bundle file gets passed, the bundle will be created with the given name. Otherwise, the bundle file name is derived from the image name. Note both bundle options can be extended with
dry-run: only perform the bundle operations without any actual native executable building
container: set up a container image and perform a native executable generation from inside that container. Requires Podman or rootless Docker to be installed. If available, Podman is preferred and rootless Docker is the fallback. Specifying one or the other as
=<container-tool>forces the use of a specific tool.
dockerfile=<Dockerfile>: use a user provided
Dockerfileinstead of the default based on Oracle Linux 8 base images for GraalVM
--bundle-apply=some-bundle.nib[,dry-run][,container[=<container-tool>][,dockerfile=<Dockerfile>]]: an image will be built from the given bundle file with the exact same arguments and files that have been passed to Native Image originally to create the bundle. Note that if an extra
--bundle-creategets passed after
--bundle-apply, a new bundle will be written based on the given bundle args plus any additional arguments that haven been passed afterwards. For example:
native-image --bundle-apply=app.nib --bundle-create=app_dbg.nib -gcreates a new bundle app_dbg.nib based on the given app.nib bundle. Both bundles are the same except the new one also uses the
-E<env-var-key>[=<env-var-value>]: allow Native Image to access the given environment variable during native executable generation. If the optional
<env-var-value>is not given, the value of the environment variable will be taken from the environment Native Image was invoked from.
-V<key>=<value>: provide values for placeholders in the native-image.properties files
<target-module>, regardless of module declaration.
ALL-UNNAMEDto export to all unnamed modules
<target-module>, regardless of module declaration
<target-module>, regardless of module declaration.
ALL-UNNAMEDto read all unnamed modules
Native Image options are also distinguished as hosted and runtime options.