Skip to main content

Command Line Options

The native-image command has many options to use. There are four categories of options:

  • Image generation options
  • Macro options
  • Non-standard options
  • Server options

Basic Options

info

These options are collected from the output of native-image --help.

OptionDescription
-cp, -classpath, --class-pathSet a list of directories, JAR archives, and ZIP archives to search for class files.
-p, --module-pathSet a list of directories for modules.
--add-modulesRoot modules to resolve in addition to the initial module. Module name can also be ALL-DEFAULT, ALL-SYSTEM, ALL-MODULE-PATH.
-D<name>=<value>Set a system property
-J<flag>Pass <flag> to the JVM running the native image builder
--diagnostics-modeEnable diagnostics output: class initialization, substitutions, etc.
--enable-previewAllow classes to depend on preview features of this release
--enable-native-accessSet modules that are permitted to perform restricted native operations. Module name can also be ALL-UNNAMED.
-O<level>b for fastest build time, 0 for no optimizations, 1 for basic optimizations, 2 for advanced optimizations, 3 for all optimizations for best performance
--verboseEnable verbose output
--versionDisplay the product version
--helpDisplay help message
--help-extraDisplay help of non-standard options
--colorSet color build output (always, never, or auto)
--allow-incomplete-classpathBuild with an incomplete class path. Type resolution errors will be reported at runtime when they are accessed the first time.
--auto-fallbackBuild a standalone image if possible
--force-fallbackForce building of a fallback image
--no-fallbackBuild a standalone image or report a failure
--enable-httpEnable HTTP support
--enable-httpsEnable HTTPS support
--enable-monitoringEnable monitoring features that allow the VM to be inspected at run time. Comma-separated list can contain heapdump, jfr, jvmstat, jmxserver (experimental), jmxclient (experimental), or all.
--enable-sbomEmbed a Software Bill of Materials (SBOM) in the executable or shared library for passive inspection. A comma-separated list can contain cyclonedx, strict or export.
--enable-url-protocolsList of comma separated URL protocols to enable. Currently, only file and resource are enabled by default.
--gc=<value>Select native-image garbage collector implementation
--featuresSet a comma-separated list of fully qualified Feature implementation classes
--initialize-at-build-timeA comma-separated list of packages and classes (and implicitly all of their superclasses) that are initialized at image build time. An empty string means all packages.
--initialize-at-run-timeA comma-separated list of packages and classes (and implicitly all of their subclasses) that must be initialized at runtime.
--install-exit-handlersInstall signal handlers. This option is recommended for native images running in containerized environments, like Docker containers.
--libcSelect the libc implementation to use when building static images. Possible values are glibc, musl, and bionic.
--report-unsupported-elements-at-runtimeReport the usage of unsupported methods and fields at runtime when they are accessed the first time.
--sharedBuild a shared library
--staticBuild statically linked executable
--targetSelect the native image compilation target.The format is <OS>-<architecture>. The default value is host's OS-architecture pair.
-gGenerate debugging information
--trace-class-initializationA comma-separated list of fully-qualified class names that class initialization is traced for.
--trace-object-instantiationA comma-separated list of fully-qualified class names that object instantiation is traced for.
--enable-all-security-servicesAdd all security service classes
--configure-reflection-metadataEnable runtime instantiation of reflection objects for non-invoked methods.
-oSet name of the output file to be generated
--strict-image-heapEnable 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.
--parallelismSet the maximum number of threads to use concurrently during native image generation
--link-at-build-timeRequire types to be fully defined at image build-time. If used without args, all classes in scope of the option are required to be fully defined.
--link-at-build-time-pathsRequire all types in given class or module-path entries to be fully defined at image build-time.
--list-modulesList observable modules and exit.
--list-cpu-featuresShow CPU features specific to the target platform and exit.
--native-image-infoShow native-toolchain information and image-build settings.

Non-standard Options

Non-standard options can be checked by running native-image expert-options or native-image expert-options-all.

warning

Non-standard options may be deprecated or removed in different GraalVM releases.

There are two types of non-standard options:

  • Hosted options
  • Runtime options

Hosted options configure a native image build. These options are set using the prefix -H:.

Runtime options get their initial value in the image build time, using the prefix -R:. The initial value can be overridden using the -XX: prefix when executing the native executable.

Boolean options are toggled using + or -. + means enabled, while - means disabled. For example, AOTInline is a hosted boolean option, it can be enabled using -H:+AOTInline, or disabled using -H:-AOTInline.

Other options are specified using the name=value format. For example, Class is a hosted option. It can be used like -H:Class=Main. The runtime MaximumHeapSizePercent option can be used like -R:MaximumHeapSizePercent=80.