Version
- Latest
- 22.3
- 22.2
- 22.1
- 22.0
- 21.3
- Dev Build
- User Guides
- Access Environment Variables
- Add Logging to a Native Executable
- Build a Native Executable from a JAR File
- Build and Run Native Executables with JFR
- Build Java Modules into a Native Executable
- Build a Polyglot Native Executable
- Build a Native Shared Library
- Build a Statically Linked or Mostly-Statically Linked Native Executable
- Configure Native Image with the Tracing Agent
- Configure Dynamic Proxies Manually
- Containerise a Native Executable and Run in a Docker Container
- Create a Heap Dump
- Debug Native Executables with GDB
- Include Resources in a Native Executable
- Optimize a Native Executable with PGO
- Use GraalVM Dashboard to Optimize the Size of a Native Executable
- Configure Native Image Using Shared Reachability Metadata
- Use System Properties
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.