Skip to content

Commit 0c2731c

Browse files
committed
[GR-60094] Test and review Native Image guides with JDK 24-EA. Part 2
PullRequest: graal/19511
2 parents 77e1870 + 6e80c59 commit 0c2731c

9 files changed

+71
-66
lines changed

docs/getting-started/oci/cloud-shell.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ You are all set to run Java applications using Oracle GraalVM JDK in Cloud Shell
5050

5151
## Run a Java Application
5252

53-
The example is a minimal REST-based application, built on top of Spring Boot using Maven.
53+
The example is a minimal REST-based application, built on top of Spring Boot 3 using Maven.
5454
The _pom.xml_ file was generated using [Spring Initializr](https://start.spring.io/) with Spring Native Tools added as a feature.
5555
The [Spring AOT plugin](https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#spring-aot) performs ahead-of-time transformations of a Spring application into a native executable.
5656

5757
1. Clone the _demos_ repository and change to the application root directory:
5858
```shell
5959
git clone https://github.com/graalvm/graalvm-demos.git
60-
cd graalvm-demos/spring-native-image
60+
cd graalvm-demos/native-image/containerize
6161
```
6262
2. Build the application with Maven (Apache Maven is also preinstalled in Cloud Shell):
6363
```shell
64-
mvn clean package
64+
./mvnw clean package
6565
```
6666
This will generate a runnable JAR file that contains all of the application’s dependencies as well as a correctly configured `MANIFEST` file.
6767

@@ -85,7 +85,7 @@ The [Spring AOT plugin](https://docs.spring.io/spring-native/docs/current/refere
8585

8686
4. Next, build a native executable for this Spring Boot application using the [`native` Maven profile](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html#quickstart).
8787
```shell
88-
mvn -Pnative native:compile
88+
./mvnw -Pnative native:compile
8989
```
9090
This will generate a native executable for Linux in the _target_ directory, named _benchmark-jibber_.
9191

@@ -115,5 +115,4 @@ Thus, you can use Oracle GraalVM in OCI Cloud Shell to build and test simple Jav
115115
- [Java Hello World with Oracle GraalVM in OCI Cloud Shell](https://github.com/graalvm/graalvm-demos/blob/master/java-hello-world-maven/README-Cloud-Shell.md)
116116
- [Micronaut Hello World REST App with Oracle GraalVM in OCI Cloud Shell](https://github.com/graalvm/graalvm-demos/blob/master/micronaut-hello-rest-maven/README-Cloud-Shell.md)
117117
- [Spring Boot Microservice with Oracle GraalVM in OCI Cloud Shell](https://github.com/graalvm/graalvm-demos/blob/master/spring-native-image/README-Cloud-Shell.md)
118-
- [Oracle GraalVM in OCI Code Editor](code-editor.md)
119-
118+
- [Oracle GraalVM in OCI Code Editor](code-editor.md)

docs/reference-manual/native-image/guides/containerise-native-executable-with-docker.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ You will use a GraalVM container image with Native Image to compile a Java appli
2020

2121
## Download a Sample Application
2222

23-
This guide uses the [Spring Boot 3 Native Image Microservice example](https://github.com/graalvm/graalvm-demos/blob/master/spring-native-image/README.md).
23+
This guide uses the [Spring Boot 3 Native Image Microservice example](https://github.com/graalvm/graalvm-demos/tree/master/native-image/containerize/src/main/java/com/example/benchmarks/jibber).
2424
The example is a minimal REST-based API application, built on top of Spring Boot 3.
2525
If you call the HTTP endpoint `/jibber`, it will return some nonsense verse generated in the style of the Jabberwocky poem, by Lewis Carroll.
2626

@@ -33,12 +33,12 @@ For other installation options, visit the [Downloads section](https://www.graalv
3333

3434
2. Clone the GraalVM Demos repository:
3535
```shell
36-
git clone https://github.com/graalvm/graalvm-demos
36+
git clone https://github.com/graalvm/graalvm-demos.git
3737
```
3838

39-
3. Change directory to _spring-native-image/_:
39+
3. Change directory to _native-image/containerize/_:
4040
```shell
41-
cd spring-native-image
41+
cd graalvm-demos/native-image/containerize
4242
```
4343

4444
## Build and Run as a Native Executable
@@ -71,9 +71,9 @@ With the built-in support for GraalVM Native Image in Spring Boot 3, it has beco
7171

7272
The generated native executable is platform-dependent.
7373

74-
1. Containerize the native executable using the following command:
74+
1. Containerize the native executable using the following commands.
7575

76-
- On Linux, containerize the native executable generated in the previous step using the following command:
76+
- On Linux, containerize the native executable generated in the previous step:
7777
```shell
7878
docker build -f Dockerfiles/Dockerfile.native --build-arg APP_FILE=benchmark-jibber -t jibber-benchmark:native.0.0.1-SNAPSHOT .
7979
```
@@ -109,10 +109,10 @@ The generated native executable is platform-dependent.
109109

110110
In this guide, you saw how to use GraalVM container images to containerize a native executable for your Java application.
111111

112-
With GraalVM Native Image you can build a statically linked native executable by packaging the native executable directly into tiny containers such as scratch or distroless images.
112+
With GraalVM Native Image you can also [build fully static native executables](build-static-and-mostly-static-executable.md) and package them directly into tiny containers such as scratch or distroless containers.
113113

114114
### Related Documentation
115115

116-
* [Build a Static or Mostly-Static Native Executable](build-static-and-mostly-static-executable.md)
117-
* <a href="https://docs.oracle.com/en/graalvm/jdk/17/docs/getting-started/container-images/" target="_blank">Oracle GraalVM Container Images</a>
118-
* <a href="https://luna.oracle.com/lab/fdfd090d-e52c-4481-a8de-dccecdca7d68" target="_blank">Hands-on Lab: GraalVM Native Image, Spring and Containerisation</a>
116+
* [Build a Native Executable from a Spring Boot Application](build-spring-boot-application-aot.md)
117+
* <a href="https://docs.oracle.com/en/graalvm/jdk/23/docs/getting-started/container-images/" target="_blank">Oracle GraalVM Container Images</a>
118+
* <a href="https://luna.oracle.com/lab/fdfd090d-e52c-4481-a8de-dccecdca7d68" target="_blank">Hands-on Lab: GraalVM Native Image, Spring and Containerisation</a>

docs/reference-manual/native-image/guides/create-heap-dump-from-native-executable.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ All approaches are described below.
2525
> Note: By default, a heap dump is created in the current working directory. The `-XX:HeapDumpPath` option can be used to specify an alternative filename or directory. For example:
2626
> `./helloworld -XX:HeapDumpPath=$HOME/helloworld.hprof`
2727
28-
> Also note: It is not possible to create a heap dump on the Microsoft Windows platform.
28+
> Creating a heap dump on the Microsoft Windows platform is not supported.
2929
3030
## Create a Heap Dump with VisualVM
3131

@@ -168,8 +168,8 @@ For other installation options, visit the [Downloads section](https://www.graalv
168168
native-image SVMHeapDump --enable-monitoring=heapdump
169169
```
170170

171-
(The `native-image` builder creates a native executable from the file _SVMHeapDump.class_.
172-
When the command completes, the native executable _svmheapdump_ is created in the current directory.)
171+
The `native-image` builder creates a native executable from the file _SVMHeapDump.class_.
172+
When the command completes, the native executable _svmheapdump_ is created in the current directory.
173173

174174
3. Run the application, send it a signal, and check the heap dump:
175175

docs/reference-manual/native-image/guides/include-reachability-metadata-maven.md

+9-10
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ For other installation options, visit the [Downloads section](https://www.graalv
126126
<version>1.0.0-SNAPSHOT</version>
127127

128128
<properties>
129-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
130129
<h2.version>2.2.220</h2.version>
131-
<imageName>h2example</imageName>
130+
<maven.compiler.source>21</maven.compiler.source>
131+
<maven.compiler.target>21</maven.compiler.target>
132+
<native.maven.plugin.version>0.10.3</native.maven.plugin.version>
132133
<mainClass>org.graalvm.example.H2Example</mainClass>
134+
<imageName>h2example</imageName>
133135
</properties>
134136

135137
<dependencies>
@@ -184,10 +186,6 @@ For other installation options, visit the [Downloads section](https://www.graalv
184186
<groupId>org.apache.maven.plugins</groupId>
185187
<artifactId>maven-compiler-plugin</artifactId>
186188
<version>3.11.0</version>
187-
<configuration>
188-
<source>${java.version}</source>
189-
<target>22</target>
190-
</configuration>
191189
</plugin>
192190

193191
<plugin>
@@ -327,15 +325,15 @@ In the `native` Maven profile section, add the `exec-maven-plugin` plugin:
327325
</plugin>
328326
```
329327
330-
3. Run your application with the agent enabled, on the JVM:
328+
3. Run your application with the agent on the JVM:
331329
```shell
332-
mvn -Pnative -Dagent=true -DskipTests -DskipNativeBuild=true package exec:exec@java-agent
330+
mvn -Pnative -DskipTests -DskipNativeBuild=true package exec:exec@java-agent
333331
```
334332
The agent captures and records calls to the H2 Database and all the dynamic features encountered during a test run into the _reachability-metadata.json_ file in the _target/native/agent-output/main/_ directory.
335333
336334
4. Build a native executable using configuration collected by the agent:
337335
```shell
338-
mvn -Pnative -Dagent=true -DskipTests package exec:exec@native
336+
mvn -Pnative -DskipTests package exec:exec@native
339337
```
340338
It generates a native executable for the platform in the _target/_ directory, called _h2example_.
341339
@@ -346,7 +344,8 @@ In the `native` Maven profile section, add the `exec-maven-plugin` plugin:
346344
347345
### Summary
348346
349-
This guide demonstrated how to build a native executable using the [GraalVM Reachability Metadata Repository](https://github.com/oracle/graalvm-reachability-metadata) and with the Tracing Agent. The goal was to show the difference, and prove how using the reachability metadata can simplify the work.
347+
This guide demonstrated how to build a native executable using the [GraalVM Reachability Metadata Repository](https://github.com/oracle/graalvm-reachability-metadata) and with the Tracing Agent.
348+
The goal was to show the difference, and prove how using the reachability metadata can simplify the work.
350349
Using the GraalVM Reachability Metadata Repository enhances the usability of Native Image for Java applications depending on 3rd party libraries.
351350
352351
### Related Documentation

docs/reference-manual/native-image/guides/include-resources.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ permalink: /reference-manual/native-image/guides/include-resources/
77

88
# Include Resources in a Native Executable
99

10-
By default, the `native-image` tool does not integrate any Java resource files into a native executable.
11-
You must specify resources that should be accessible by your application at runtime.
10+
By default, the `native-image` tool does not integrate any resource files into a native executable.
11+
You must specify resources that should be accessible by your application at run time.
1212

1313
This guide demonstrates how to register resources to be included in a native executable by providing a resource configuration file.
1414
See [Accessing Resources in Native Image](../ReachabilityMetadata.md#resources) for more ways to include resources.
@@ -47,8 +47,8 @@ In the following example, you run a "fortune teller" application that simulates
4747
}
4848

4949
private void printRandomFortune() throws InterruptedException {
50-
int r = RANDOM.nextInt(fortunes.size()); //Pick a random number
51-
String f = fortunes.get(r); //Use the random number to pick a random fortune
50+
int r = RANDOM.nextInt(fortunes.size()); // Pick a random number
51+
String f = fortunes.get(r); // Use the random number to pick a random fortune
5252
for (char c: f.toCharArray()) { // Print out the fortune
5353
System.out.print(c);
5454
Thread.sleep(100);
@@ -93,11 +93,12 @@ In the following example, you run a "fortune teller" application that simulates
9393

9494
To see which resources were included in your native executable, pass the option `--emit build-report` to the `native-image` tool at build time.
9595
It generates an HTML file that can be examined with a regular web browser.
96-
The information about all included resources will be under the `Resources` tab.
96+
The information about all included resources will be under the **Resources** tab.
9797

98-
In this demo the path to the resource file is straightforward, but it may be more complex in a real-world use case.
99-
Resources are specified via globs. For more advanced use-cases, you can register resources using the API methods (see [class RuntimeResourceAccess](https://www.graalvm.org/sdk/javadoc/org/graalvm/nativeimage/hosted/RuntimeResourceAccess.html)).
100-
Learn more about specifying a resource path using a glob and some syntax rules to be observed from [Accessing Resources in Native Image](../ReachabilityMetadata.md#resources).
98+
In this demo the path to the resource file is straightforward, but it may be more complex in real-world use cases.
99+
Resources are specified via globs.
100+
For more advanced use-cases, you can register resources using the API methods (see [class RuntimeResourceAccess](https://www.graalvm.org/sdk/javadoc/org/graalvm/nativeimage/hosted/RuntimeResourceAccess.html)).
101+
Learn more about specifying a resource path using a glob and some syntax rules to be observed in [Accessing Resources in Native Image](../ReachabilityMetadata.md#resources).
101102

102103
### Related Documentation
103104

docs/reference-manual/native-image/guides/optimize-file-size.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ For the demo, run a "fortune teller" application that simulates the traditional
2727

2828
2. Change directory to _fortune-demo/fortune-maven_:
2929
```bash
30-
cd fortune-demo/fortune-maven
30+
cd native-image/native-build-tools/maven-plugin
3131
```
3232

3333
## Build a Native Executable with Default Configuration
3434

35-
1. Create a native executable using the [Maven plugin for Native Image](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html){:target="_blank"}:
35+
1. Create a native executable using the [Maven plugin for Native Image building](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html){:target="_blank"}:
3636
```bash
37-
mvn -Pnative package
37+
./mvnw -Pnative package
3838
```
3939
The command compiles the project, creates a JAR file with all dependencies, and then generates a native executable, `fortune`, in the _target_ directory.
4040

@@ -53,7 +53,7 @@ For the demo, run a "fortune teller" application that simulates the traditional
5353

5454
Next create a native executable with the size optimization on, giving a different name for the output file to differentiate it from the previous build.
5555

56-
1. Open the _pom.xml_ file. Find the `native-maven-plugin` declaration, and add the following build arguments within the `<configuration>` element. The configuration should look like this:
56+
1. Open the _pom.xml_ file. Find the `native-maven-plugin` declaration, and notice the following build arguments within the `<configuration>` element:
5757
```xml
5858
<configuration>
5959
<imageName>fortune-optimized</imageName>
@@ -68,7 +68,7 @@ Next create a native executable with the size optimization on, giving a differen
6868

6969
2. Create the second native executable:
7070
```bash
71-
mvn -Pnative package
71+
./mvnw -Pnative package
7272
```
7373
The command generates an executable file, `fortune-optimized`, in the _target_ directory.
7474

docs/reference-manual/native-image/guides/optimize-native-executable-size-using-build-report.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ The words are delimited by commas and may be enclosed by an arbitrary number of
6565
native-image IthWord --emit build-report
6666
```
6767

68-
The command generates an executable file, `_ithword_`, in the current working directory.
68+
The command generates an executable file, `ithword`, in the current working directory.
6969
The Build Report file, _ithword-build-report.html_, is automatically created alongside the native executable.
7070
A link to the report is also listed in the _Build artifacts_ section at the end of the build output.
71-
You can specify a different filename or path for the report by appending it to the `build-report` argument, for example, `--emit build-report=/tmp/custom-name-build-report.html`.
71+
You can specify a different filename or path for the report by appending it to the `build-report` option, for example, `--emit build-report=/tmp/custom-name-build-report.html`.
7272

7373
(Optional) Run this executable with the same argument:
7474
```shell

0 commit comments

Comments
 (0)