Skip to content

Commit a1176c7

Browse files
committed
Preserve option in useful options
1 parent 2a65da5 commit a1176c7

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

docs/reference-manual/native-image/BuildOptions.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,25 @@ For example:
134134
* `-H:Dump= -H:MethodFilter=ClassName.MethodName`: dump the compiler graphs of the `native-image` builder.
135135
* `-XX:Dump= -XX:MethodFilter=ClassName.MethodName`: dump the compile graphs at runtime.
136136

137+
### Preserving Packages, Modules, or Classes
138+
139+
GraalVM for JDK 25 introduces the `-H:Preserve` option. This lets you instruct the `native-image` tool to keep entire packages, modules, or all classes on the classpath in the native executable, even when static analysis cannot discover them.
140+
141+
You can use `-H:Preserve` in the following ways:
142+
143+
* `-H:Preserve=all`: preserves all elements from the JDK and from the classpath
144+
* `-H:Preserve=module=<module>`: preserves all elements from a given module
145+
* `-H:Preserve=module=ALL-UNNAMED`: preserves all elements from the classpath (provided with `-cp`).
146+
* `-H:Preserve=package=<package>`: preserves all elements from a given package
147+
* `-H:Preserve=path=<cp-entry>`: preserves all elements from a given class-path entry
148+
* You can combine any of the previous uses by separating them with a comma (`,`). For example: `-H:Preserve=path=<cp-entry>,module=<module>,module=<module2>,package=<package>`
149+
150+
You must explicitly configure multi-interface proxy classes, arrays of dimension 3 and higher, and _.class_ files as resources in the native image. Tooling-related Java modules are not included by default with `-H:Preserve=all` and must be added with `-H:Preserve=module=<module>` if needed.
151+
152+
If you get errors related to `--initialize-at-build-time`, follow the suggestions in the error messages.
153+
154+
For a practical demonstration, see the [preserve-package demo](https://github.com/graalvm/graalvm-demos/tree/master/native-image/preserve-package).
155+
137156
## System Properties
138157

139158
You can define system properties at image build time using the `-D<system.property>=<value>` option syntax.

docs/reference-manual/native-image/guides/guides.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: ni-docs-landing
2+
layout: docs
33
toc_group: how-to-guides
44
link_title: Guides
55
permalink: /guides/

0 commit comments

Comments
 (0)