Skip to content

Commit 9c8403c

Browse files
committed
Add Access Environment Variables Native Image demo
1 parent cfc4fc6 commit 9c8403c

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.class
2+
envmap
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
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/).
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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

0 commit comments

Comments
 (0)