Skip to content

Commit 7e527e2

Browse files
authored
Merge pull request #316 from graalvm/ni-demos-refactoring-13
[GR-60094] Refactor and move hello-graal demo to native-image category.
2 parents 77ec366 + 9468e15 commit 7e527e2

File tree

9 files changed

+74
-111
lines changed

9 files changed

+74
-111
lines changed
Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
name: hello-graal
1+
name: native-image/hello-world
22
on:
33
push:
44
paths:
5-
- 'hello-graal/**'
6-
- '.github/workflows/hello-graal.yml'
5+
- 'native-image/hello-world/**'
6+
- '.github/workflows/native-image-hello-world.yml.yml'
77
pull_request:
88
paths:
9-
- 'hello-graal/**'
10-
- '.github/workflows/hello-graal.yml'
9+
- 'native-image/hello-world/**'
10+
- '.github/workflows/native-image-hello-world.yml.yml'
1111
schedule:
1212
- cron: "0 0 1 * *" # run every month
1313
workflow_dispatch:
1414
permissions:
1515
contents: read
1616
jobs:
1717
run:
18-
name: Run 'hello-graal'
18+
name: Run 'native-image/hello-world'
1919
runs-on: ubuntu-latest
2020
timeout-minutes: 15
2121
strategy:
2222
matrix:
23-
java-version: ['21', 'dev']
23+
java-version: ['21', '24-ea']
2424
steps:
2525
- uses: actions/checkout@v4
2626
- uses: graalvm/setup-graalvm@v1
@@ -29,12 +29,7 @@ jobs:
2929
distribution: 'graalvm'
3030
github-token: ${{ secrets.GITHUB_TOKEN }}
3131
native-image-job-reports: 'true'
32-
- name: Run 'hello-graal'
32+
- name: Run 'native-image/hello-world'
3333
run: |
34-
cd hello-graal
35-
javac -d build src/com/hello/Graal.java
36-
java -cp ./build com.hello.Graal
37-
jar cfvm Hello.jar manifest.txt -C build .
38-
jar tf Hello.jar
39-
native-image -jar Hello.jar
40-
./Hello
34+
cd native-image/hello-world
35+
./run.sh

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ cd graalvm-demos
2828
<td align="left" width="70%">Demonstrates how to build very small Docker container images with GraalVM Native Image and various lightweight base images. <br><strong>Technologies: </strong> Native Image, musl libc<br><strong>Reference: </strong><a href="https://www.graalvm.org/22.0/reference-manual/native-image/StaticImages/">Static and Mostly Static Images</a></td>
2929
</tr>
3030
<tr>
31-
<td align="left" width="30%"><a href="/hello-graal/">hello-graal</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/hello-graal.yml"><img alt="hello-graal" src="https://github.com/graalvm/graalvm-demos/actions/workflows/hello-graal.yml/badge.svg" /></a></td>
32-
<td align="left" width="70%">Demonstrates how to build native executables from a class file and a JAR file from the command line <br><strong>Technologies: </strong> Native Image <br><strong>Reference: </strong><a href="https://www.graalvm.org/dev/reference-manual/native-image/#build-a-native-executable">Native Image Getting Started</a></td>
31+
<td align="left" width="30%"><a href="/native-image/hello-world/">native-image/hello-world</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/native-image-hello-world.yml"><img alt="native-image/hello-world" src="https://github.com/graalvm/graalvm-demos/actions/workflows/native-image-hello-world.yml/badge.svg" /></a></td>
32+
<td align="left" width="70%">Demonstrates how to build native executables from a class file and a JAR file from the command line <br><strong>Technologies: </strong> Native Image <br><strong>Reference: </strong><a href="https://www.graalvm.org/latest/reference-manual/native-image/#build-a-native-executable-using-the-native-image-tool">Native Image Getting Started</a></td>
3333
</tr>
3434
<tr>
3535
<td align="left" width="30%"><a href="/java-hello-world-maven/">java-hello-world-maven</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/java-hello-world-maven.yml"><img alt="java-hello-world-maven" src="https://github.com/graalvm/graalvm-demos/actions/workflows/java-hello-world-maven.yml/badge.svg" /></a></td>

hello-graal/README.md

Lines changed: 0 additions & 87 deletions
This file was deleted.

hello-graal/manifest.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

native-image/hello-world/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HelloWorld

native-image/hello-world/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Build a Native Executable Using the `native-image` Tool
2+
3+
This is a HelloWorld Java example, referenced from [Getting Started with Native Image](https://www.graalvm.org/latest/reference-manual/native-image/).
4+
5+
## Run the Application from a Class File
6+
7+
1. Compile the application running the follow command:
8+
```bash
9+
javac -d build src/com/example/HelloWorld.java
10+
```
11+
This generates the `HelloWorld.class` file into `build/com/example` directory.
12+
13+
2. Run the application from a class file:
14+
```bash
15+
java -cp ./build com.example.HelloWorld
16+
```
17+
It outputs the message "Hello, Native World!".
18+
19+
## Run the Application from JAR
20+
21+
1. Create a JAR for the application, running the follow command:
22+
```bash
23+
jar --create --file HelloWorld.jar --main-class com.example.HelloWorld -C build .
24+
```
25+
2. Run the JAR file:
26+
```bash
27+
java -jar HelloWorld.jar
28+
```
29+
30+
## Run the Application as a Native Executable
31+
32+
1. Create a native executable of a JAR file:
33+
```bash
34+
native-image -jar HelloWorld.jar
35+
```
36+
The executable called `./HelloWorld` will be created in the working directory.
37+
38+
2. Execute it:
39+
```bash
40+
./HelloWorld
41+
```

native-image/hello-world/manifest.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Manifest-version: 1.0
2+
Main-Class: com.example.HelloWorld

native-image/hello-world/run.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
# Run from a class file
5+
javac -d build src/com/example/HelloWorld.java
6+
java -cp ./build com.example.HelloWorld
7+
8+
# Run from a JAR file
9+
jar --create --file HelloWorld.jar --main-class com.example.HelloWorld -C build .
10+
java -jar HelloWorld.jar
11+
12+
# Run from a native executable
13+
native-image -jar HelloWorld.jar
14+
./HelloWorld

hello-graal/src/com/hello/Graal.java renamed to native-image/hello-world/src/com/example/HelloWorld.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -38,10 +38,10 @@
3838
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3939
* SOFTWARE.
4040
*/
41-
package com.hello;
41+
package com.example;
4242

43-
public class Graal {
43+
public class HelloWorld {
4444
public static void main(String[] args) {
45-
System.out.println("hello graal");
45+
System.out.println("Hello, Native World!");
4646
}
4747
}

0 commit comments

Comments
 (0)