Skip to main content

native-image

native-image is the tool to build native images. This tool has already bundled in GraalVM.

Basic Usage

Below are the basic syntax to use this tool. To build native image, a class, a JAR file or a module needs to be provided. This class is the entrypoint of the native image. When using a JAR file, this JAR file must have the Main-Class header in the manifest. The usage of class name and JAR file is similar to java command.

TypeCommand
Classnative-image [options] class [imagename] [options]
JAR filenative-image [options] -jar jarfile [imagename] [options]
Modulenative-image [options] -m <module>[/<mainclass>] [options] or native-image [options] --module <module>[/<mainclass>] [options]

The class name can also be specified using the option -H:Class. The image name can also be specified using the option -H:Name.

native-image -H:Name=my-app -H:Class=com.myapp.Main

Fallback Image

If a native image cannot be generated due to some limitations of native images, a fallback image will be generated instead. This fallback image requires a JDK for execution. If this is not the desired behavior, the --no-fallback option can be used to suppress fallback image generation. In this case, the native image generation may fail.

To show more detailed information about image generation errors, the -H:+ReportExceptionStackTraces option can be used to show stacktraces.

Build Output

GraalVM 22 introduces a new layout of native-image output.

Build output

This new output style can be customized with options prefixed with BuildOutput. For example, if you don't want the colorful output, the -H:-BuildOutputColorful option can disable it.

info

If you want to see all options related to build output, go to Expert Options page for GraalVM 22, and search for BuildOutput.