This documentation is for an old GraalVM version. See the latest version.

Specify Class Initialization Explicitly

Two command line flags explicitly specify when a class should be initialized: --initialize-at-build-time and --initialize-at-run-time. You can use the flags to specify whole packages or individual classes. For example, if you have the classes p.C1, p.C2, … ,p.Cn, you can specify that all the classes in the package p are initialized at build time by passing the following argument to native-image on the command line:

--initialize-at-build-time=p

If you want only one of the classes in package p to be initialized at runtime, use:

--initialize-at-run-time=p.C1

The whole class hierarchy can be initialized at build time by passing --initialize-at-build-time on the command line.

Class initialization can also be specified programmatically using RuntimeClassInitialization from the Native Image feature.

Connect with us