You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Assume you have compiled the following Java application using `javac`:
12
-
```java
13
-
publicclassApp {
14
-
publicstaticvoidmain(String[] args) {
15
-
System.getProperties().list(System.out);
16
-
}
17
-
}
18
-
```
19
-
20
-
If you build a native executable using `native-image -Dfoo=bar App`, the system property `foo` will **only** be available at build time.
21
-
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
-
But if you run the resulting executable, it will not contain `foo` in the printed list of properties.
23
-
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.
25
-
26
-
## Read System Properties at Build Time
27
-
28
-
You can read system properties at build time and incorporate them into the native executable, as shown in the following example.
29
-
30
-
### Prerequisite
31
-
Make sure you have installed a GraalVM JDK.
32
-
The easiest way to get started is with [SDKMAN!](https://sdkman.io/jdks#graal).
33
-
For other installation options, visit the [Downloads section](https://www.graalvm.org/downloads/).
34
-
35
-
1. Save the following Java code into a file named _ReadProperties.java_:
System.out.println("Value of instance property: "+ instanceProperty);
54
-
}
55
-
56
-
publicstaticvoidmain(String[] args) {
57
-
System.out.println("Value of static property: "+STATIC_PROPERTY);
58
-
ReadProperties rp =newReadProperties();
59
-
rp.print();
60
-
}
61
-
}
62
-
```
63
-
64
-
2.Compile the application:
65
-
```shell
66
-
javac ReadProperties.java
67
-
```
68
-
69
-
3.Build the native executable, passing a system property as a command-line option. Then run the native executable, passing a different system property on the command line.
0 commit comments