File tree Expand file tree Collapse file tree 5 files changed +64
-0
lines changed
native-image/access-environment-variables Expand file tree Collapse file tree 5 files changed +64
-0
lines changed Original file line number Diff line number Diff line change 1+ name : native-image/access-environment-variables
2+ on :
3+ push :
4+ paths :
5+ - ' native-image/access-environment-variables/**'
6+ - ' .github/workflows/access-environment-variables.yml'
7+ pull_request :
8+ paths :
9+ - ' native-image/access-environment-variables/**'
10+ - ' .github/workflows/access-environment-variables.yml'
11+ schedule :
12+ - cron : " 0 0 1 * *" # run every month
13+ workflow_dispatch :
14+ permissions :
15+ contents : read
16+ jobs :
17+ run :
18+ name : Run 'native-image/access-environment-variables'
19+ runs-on : ubuntu-latest
20+ timeout-minutes : 15
21+ strategy :
22+ matrix :
23+ java-version : ['21', '24-ea']
24+ steps :
25+ - uses : actions/checkout@v4
26+ - uses : graalvm/setup-graalvm@v1
27+ with :
28+ java-version : ${{ matrix.java-version }}
29+ distribution : ' graalvm'
30+ github-token : ${{ secrets.GITHUB_TOKEN }}
31+ native-image-job-reports : ' true'
32+ - name : Run 'native-image/access-environment-variables'
33+ run : |
34+ cd native-image/access-environment-variables
35+ ./run.sh
Original file line number Diff line number Diff line change 1+ .class
2+ envmap
Original file line number Diff line number Diff line change 1+ import java .util .Map ;
2+
3+ public class EnvMap {
4+ public static void main (String [] args ) {
5+ var filter = args .length > 0 ? args [0 ] : "" ;
6+ Map <String , String > env = System .getenv ();
7+ for (String envName : env .keySet ()) {
8+ if (envName .contains (filter )) {
9+ System .out .format ("%s=%s%n" ,
10+ envName ,
11+ env .get (envName ));
12+ }
13+ }
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ # Access Environment Variables in a Native Executable at Runtime
2+
3+ You can find the steps to run this demo on [ the website] ( https://www.graalvm.org/latest/reference-manual/native-image/guides/access-environment-variables/ ) .
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -ex
3+
4+ $JAVA_HOME /bin/javac EnvMap.java
5+ $JAVA_HOME /bin/native-image -Ob EnvMap
6+
7+ ./envmap HELLO
8+ export HELLOWORLD=' Hello World!'
9+ ./envmap HELLO
You can’t perform that action at this time.
0 commit comments