|
1 | | -# Microanut Layered Native Image Demo |
| 1 | +# Micronaut Layered Native Image Demo |
2 | 2 |
|
3 | 3 | This example shows how to build a simple [Micronaut](https://micronaut.io/) REST application using the [GraalVM Native Image Layers](https://github.com/oracle/graal/blob/master/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/imagelayer/NativeImageLayers.md) feature. |
4 | 4 |
|
| 5 | +### Prerequisites |
| 6 | +- SDKMAN! (for installing Micronaut CLI) |
| 7 | +- Latest GraalVM 25.1 EA build (with Native Image support) |
| 8 | + |
| 9 | +> Native Image Layers is an experimental feature. For the best experience use the latest [GraalVM Early Access Build](https://github.com/graalvm/oracle-graalvm-ea-builds/releases). |
| 10 | +
|
5 | 11 | ## Environment Setup |
6 | | -Point your `JAVA_HOME` to a GraalVM distribution. |
7 | | -Native Image Layers is an experimental feature, for best experience use the latest [GraalVM Early Access Build](https://github.com/graalvm/oracle-graalvm-ea-builds/releases). |
| 12 | +Point your `JAVA_HOME` to the GraalVM distribution. |
8 | 13 | ```bash |
9 | 14 | export JAVA_HOME=/path/to/graalvm/ea/build |
10 | 15 | ``` |
11 | 16 |
|
12 | | -## Create The Micronaut Application |
13 | | - |
14 | | -We'll start by generating a basic application using the Micronaut CLI. |
15 | | -For more details see the [Micronaut guide](https://guides.micronaut.io/latest/creating-your-first-micronaut-app-maven-java.html). |
16 | | - |
17 | | -First we need to install the `mn` tool: |
| 17 | +Install `mn`, the Micronaut CLI tool: |
18 | 18 | ```bash |
19 | 19 | sdk install micronaut 4.9.4 |
20 | 20 | sdk use micronaut 4.9.4 |
21 | 21 | ``` |
22 | 22 |
|
23 | | -Now we ca generate the basic app: |
| 23 | +## Create the Micronaut Application |
| 24 | + |
| 25 | +We'll start by generating a basic application using the Micronaut CLI. |
| 26 | +For more details, see the [Micronaut guide](https://guides.micronaut.io/latest/creating-your-first-micronaut-app-maven-java.html). |
| 27 | + |
24 | 28 | ```bash |
25 | 29 | mn create-app example.micronaut.micronaut-hello-rest-maven-layered --build=maven --lang=java --features=graalvm |
26 | 30 | ``` |
27 | 31 |
|
| 32 | +This creates a new Micronaut project with the following structure: |
| 33 | +``` |
| 34 | +micronaut-hello-rest-maven-layered/ |
| 35 | +├── pom.xml |
| 36 | +├── src/ |
| 37 | +│ ├── main/ |
| 38 | +│ │ ├── java/ |
| 39 | +│ │ │ └── example/micronaut/Application.java |
| 40 | +│ │ └── resources/ |
| 41 | +│ │ └── application.properties |
| 42 | +│ └── test/ |
| 43 | +└── mvnw (Maven wrapper) |
| 44 | +``` |
| 45 | + |
| 46 | +For executing the subsequent commnds we must enter the project directory: |
| 47 | +```bash |
| 48 | +cd micronaut-hello-rest-maven-layered |
| 49 | +``` |
| 50 | + |
28 | 51 | ### Add A Custom Controller |
29 | 52 |
|
30 | 53 | We'll add a custom controller to `src/main/java/example/micronaut/HelloController.java`: |
@@ -87,6 +110,9 @@ This will generate an executable file that we can run |
87 | 110 | and test our custom endpoint |
88 | 111 | ```bash |
89 | 112 | curl localhost:8080/hello |
| 113 | +``` |
| 114 | +The expected output is: |
| 115 | +``` |
90 | 116 | Hello from GraalVM Native Image! |
91 | 117 | ``` |
92 | 118 |
|
@@ -188,5 +214,8 @@ Then we can execute the layered application: |
188 | 214 | and test it with: |
189 | 215 | ``` |
190 | 216 | curl localhost:8080/hello |
| 217 | +``` |
| 218 | +The expected output is: |
| 219 | +``` |
191 | 220 | Hello from GraalVM Native Image! |
192 | 221 | ``` |
0 commit comments