Skip to content

Commit 36b8d97

Browse files
committed
Document system properties always included in a native image
1 parent d6f8703 commit 36b8d97

File tree

4 files changed

+45
-16
lines changed

4 files changed

+45
-16
lines changed

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

+34
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ permalink: /reference-manual/native-image/overview/Options/
66
redirect_from:
77
- /reference-manual/native-image/overview/BuildOptions/
88
- /reference-manual/native-image/Options/
9+
- /reference-manual/native-image/guides/use-system-properties/
910
---
1011

1112
# Command-line Options
@@ -133,6 +134,39 @@ For example:
133134
* `-H:Dump= -H:MethodFilter=ClassName.MethodName`: dump the compiler graphs of the `native-image` builder.
134135
* `-XX:Dump= -XX:MethodFilter=ClassName.MethodName`: dump the compile graphs at runtime.
135136

137+
## System Properties
138+
139+
You can define system properties at image build time using the `-D<system.property>=<value>` option syntax.
140+
It sets a system property for the `native-image` tool, but the property will not be included in the generated executable.
141+
However, JDK system properties are included in generated executables and are visible at runtime.
142+
143+
For example:
144+
* `-D<system.property>=<value>` will only be visible at build time. If this system property is accessed in the native executable, it will return `null`.
145+
* `-Djava.version=24` will be visible at both build time and in the native executable because the value is copied into the binary by default.
146+
147+
The following system properties are automatically copied into the generated executable:
148+
149+
| Name | Description |
150+
|-------------------------------|-------------------------------------------------------------------|
151+
| file.separator | File separator |
152+
| file.encoding | Character encoding for the default locale |
153+
| java.version | Java Runtime Environment version |
154+
| java.version.date | General-availability (GA) date of the release |
155+
| java.class.version | Java class format version number |
156+
| java.runtime.version | Java Runtime Environment version |
157+
| java.specification.name | Java Runtime Environment specification name |
158+
| java.specification.vendor | Java Runtime Environment specification vendor |
159+
| java.specification.version | Java Virtual Machine specification version |
160+
| java.vm.specification.name | Java Virtual Machine specification name |
161+
| java.vm.specification.vendor | Java Virtual Machine implementation vendor |
162+
| java.vm.specification.version | Java Virtual Machine specification version |
163+
| line.separator | Line separator |
164+
| native.encoding | Specifies the host environment's character encoding |
165+
| org.graalvm.nativeimage.kind | Specifies if the image is built as a shared library or executable |
166+
| path.separator | Path separator |
167+
| stdout.encoding | Specifies the encoding for `System.out` and `System.err` |
168+
| sun.jnu.encoding | Specifies encoding when parsing values passed via the commandline |
169+
136170
## Related Documentation
137171

138172
* [Build Configuration](BuildConfiguration.md#order-of-arguments-evaluation)

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ native-image HelloWorld --initialize-at-build-time=HelloWorld\$Greeter
102102
GraalVM Native Image: Generating 'helloworld' (executable)...
103103
========================================================================================================================
104104
Greeter is getting ready!
105-
[1/7] Initializing... (3.1s @ 0.15GB)
106-
Version info: 'GraalVM dev Java 11 EE'
107-
Java version info: '11.0.15+4-jvmci-22.1-b02'
108-
C compiler: gcc (linux, x86_64, 9.4.0)
109-
Garbage collector: Serial GC
105+
[1/8] Initializing... (3.1s @ 0.15GB)
106+
Java version: 24+36, vendor version: Oracle GraalVM 24+36.1
107+
Graal compiler: optimization level: 2, target machine: armv8.1-a, PGO: ML-inferred
108+
C compiler: cc (apple, arm64, 16.0.0)
109+
Garbage collector: Serial GC (max heap size: 80% of RAM)
110110
...
111111
Finished generating 'helloworld' in 13.6s.
112112
./helloworld

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

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Here you will learn how to:
3838
- [Specify Class Initialization Explicitly](specify-class-initialization.md)
3939
- [Use Gradle to Build a Native Executable from a Java Application](https://graalvm.github.io/native-build-tools/latest/gradle-plugin-quickstart.html)
4040
- [Use Maven to Build a Native Executable from a Java Application](https://graalvm.github.io/native-build-tools/latest/maven-plugin-quickstart.html)
41-
- [Use System Properties in a Native Executable](use-system-properties.md)
4241

4342
## Microservices Frameworks
4443

docs/reference-manual/native-image/guides/use-system-properties.md

+6-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: ni-docs
33
toc_group: how-to-guides
44
link_title: Use System Properties
55
permalink: /reference-manual/native-image/guides/use-system-properties/
6-
redirect_from: /reference-manual/native-image/Properties/
6+
redirect_to: /reference-manual/native-image/overview/Options/
77
---
88

99
# Use System Properties in a Native Executable
@@ -17,19 +17,15 @@ public class App {
1717
}
1818
```
1919

20-
If you build a native executable using `native-image -Dfoo=bar App`, the system property `foo` will be available at *executable build time*.
20+
If you build a native executable using `native-image -Dfoo=bar App`, the system property `foo` will **only** be available at build time.
2121
This means it is available to the [code in your application that is run at build time](http://www.graalvm.org/sdk/javadoc/org/graalvm/nativeimage/ImageInfo.html#inImageBuildtimeCode--) (usually static field initializations and static initializers).
22-
Thus, if you run the resulting executable, it will not contain `foo` in the printed list of properties.
22+
But if you run the resulting executable, it will not contain `foo` in the printed list of properties.
2323

24-
If, on the other hand, you run the executable with `app -Dfoo=bar`, it will display `foo` in the list of properties because you specified property at *executable run time*.
25-
26-
In other words:
27-
* Pass `-D<key>=<value>` as an option to `native-image` to control the properties seen at build time.
28-
* Pass `-D<key>=<value>` as an option to a native executable to control the properties seen at run time.
24+
If, on the other hand, you run the executable with `app -Dfoo=bar`, it will display `foo` in the list of properties because you specified this property.
2925

3026
## Read System Properties at Build Time
3127

32-
You can read system properties at build time and incorporate them into the resulting executable file, as shown in the following example.
28+
You can read system properties at build time and incorporate them into the native executable, as shown in the following example.
3329

3430
### Prerequisite
3531
Make sure you have installed a GraalVM JDK.
@@ -116,5 +112,5 @@ For other installation options, visit the [Downloads section](https://www.graalv
116112

117113
### Related Documentation
118114

119-
* [Class Initialization in Native Image](../ClassInitialization.md)
115+
* [Command-line Options: System Properties](../BuildOptions.md#system-properties)
120116
* [Specify Class Initialization Explicitly](specify-class-initialization.md)

0 commit comments

Comments
 (0)