Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions docs/getting-started/oci/cloud-shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ You are all set to run Java applications using Oracle GraalVM JDK in Cloud Shell

## Run a Java Application

The example is a minimal REST-based application, built on top of Spring Boot using Maven.
The example is a minimal REST-based application, built on top of Spring Boot 3 using Maven.
The _pom.xml_ file was generated using [Spring Initializr](https://start.spring.io/) with Spring Native Tools added as a feature.
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.

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

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

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).
```shell
mvn -Pnative native:compile
./mvnw -Pnative native:compile
```
This will generate a native executable for Linux in the _target_ directory, named _benchmark-jibber_.

Expand Down Expand Up @@ -115,5 +115,4 @@ Thus, you can use Oracle GraalVM in OCI Cloud Shell to build and test simple Jav
- [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)
- [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)
- [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)
- [Oracle GraalVM in OCI Code Editor](code-editor.md)

- [Oracle GraalVM in OCI Code Editor](code-editor.md)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ You will use a GraalVM container image with Native Image to compile a Java appli

## Download a Sample Application

This guide uses the [Spring Boot 3 Native Image Microservice example](https://github.com/graalvm/graalvm-demos/blob/master/spring-native-image/README.md).
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).
The example is a minimal REST-based API application, built on top of Spring Boot 3.
If you call the HTTP endpoint `/jibber`, it will return some nonsense verse generated in the style of the Jabberwocky poem, by Lewis Carroll.

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

2. Clone the GraalVM Demos repository:
```shell
git clone https://github.com/graalvm/graalvm-demos
git clone https://github.com/graalvm/graalvm-demos.git
```

3. Change directory to _spring-native-image/_:
3. Change directory to _native-image/containerize/_:
```shell
cd spring-native-image
cd graalvm-demos/native-image/containerize
```

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

The generated native executable is platform-dependent.

1. Containerize the native executable using the following command:
1. Containerize the native executable using the following commands.

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

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

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.
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.

### Related Documentation

* [Build a Static or Mostly-Static Native Executable](build-static-and-mostly-static-executable.md)
* <a href="https://docs.oracle.com/en/graalvm/jdk/17/docs/getting-started/container-images/" target="_blank">Oracle GraalVM Container Images</a>
* <a href="https://luna.oracle.com/lab/fdfd090d-e52c-4481-a8de-dccecdca7d68" target="_blank">Hands-on Lab: GraalVM Native Image, Spring and Containerisation</a>
* [Build a Native Executable from a Spring Boot Application](build-spring-boot-application-aot.md)
* <a href="https://docs.oracle.com/en/graalvm/jdk/23/docs/getting-started/container-images/" target="_blank">Oracle GraalVM Container Images</a>
* <a href="https://luna.oracle.com/lab/fdfd090d-e52c-4481-a8de-dccecdca7d68" target="_blank">Hands-on Lab: GraalVM Native Image, Spring and Containerisation</a>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ All approaches are described below.
> 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:
> `./helloworld -XX:HeapDumpPath=$HOME/helloworld.hprof`

> Also note: It is not possible to create a heap dump on the Microsoft Windows platform.
> Creating a heap dump on the Microsoft Windows platform is not supported.

## Create a Heap Dump with VisualVM

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ For other installation options, visit the [Downloads section](https://www.graalv
<version>1.0.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<h2.version>2.2.220</h2.version>
<imageName>h2example</imageName>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<native.maven.plugin.version>0.10.3</native.maven.plugin.version>
<mainClass>org.graalvm.example.H2Example</mainClass>
<imageName>h2example</imageName>
</properties>

<dependencies>
Expand Down Expand Up @@ -184,10 +186,6 @@ For other installation options, visit the [Downloads section](https://www.graalv
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>${java.version}</source>
<target>22</target>
</configuration>
</plugin>

<plugin>
Expand Down Expand Up @@ -327,15 +325,15 @@ In the `native` Maven profile section, add the `exec-maven-plugin` plugin:
</plugin>
```

3. Run your application with the agent enabled, on the JVM:
3. Run your application with the agent on the JVM:
```shell
mvn -Pnative -Dagent=true -DskipTests -DskipNativeBuild=true package exec:exec@java-agent
mvn -Pnative -DskipTests -DskipNativeBuild=true package exec:exec@java-agent
```
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.

4. Build a native executable using configuration collected by the agent:
```shell
mvn -Pnative -Dagent=true -DskipTests package exec:exec@native
mvn -Pnative -DskipTests package exec:exec@native
```
It generates a native executable for the platform in the _target/_ directory, called _h2example_.

Expand All @@ -346,7 +344,8 @@ In the `native` Maven profile section, add the `exec-maven-plugin` plugin:

### Summary

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.
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.
Using the GraalVM Reachability Metadata Repository enhances the usability of Native Image for Java applications depending on 3rd party libraries.

### Related Documentation
Expand Down
17 changes: 9 additions & 8 deletions docs/reference-manual/native-image/guides/include-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ permalink: /reference-manual/native-image/guides/include-resources/

# Include Resources in a Native Executable

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

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

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

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

In this demo the path to the resource file is straightforward, but it may be more complex in a real-world use case.
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)).
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).
In this demo the path to the resource file is straightforward, but it may be more complex in real-world use cases.
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)).
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).

### Related Documentation

Expand Down
10 changes: 5 additions & 5 deletions docs/reference-manual/native-image/guides/optimize-file-size.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ For the demo, run a "fortune teller" application that simulates the traditional

2. Change directory to _fortune-demo/fortune-maven_:
```bash
cd fortune-demo/fortune-maven
cd native-image/native-build-tools/maven-plugin
```

## Build a Native Executable with Default Configuration

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"}:
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"}:
```bash
mvn -Pnative package
./mvnw -Pnative package
```
The command compiles the project, creates a JAR file with all dependencies, and then generates a native executable, `fortune`, in the _target_ directory.

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

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.

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:
1. Open the _pom.xml_ file. Find the `native-maven-plugin` declaration, and notice the following build arguments within the `<configuration>` element:
```xml
<configuration>
<imageName>fortune-optimized</imageName>
Expand All @@ -68,7 +68,7 @@ Next create a native executable with the size optimization on, giving a differen

2. Create the second native executable:
```bash
mvn -Pnative package
./mvnw -Pnative package
```
The command generates an executable file, `fortune-optimized`, in the _target_ directory.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ The words are delimited by commas and may be enclosed by an arbitrary number of
native-image IthWord --emit build-report
```

The command generates an executable file, `_ithword_`, in the current working directory.
The command generates an executable file, `ithword`, in the current working directory.
The Build Report file, _ithword-build-report.html_, is automatically created alongside the native executable.
A link to the report is also listed in the _Build artifacts_ section at the end of the build output.
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`.
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`.

(Optional) Run this executable with the same argument:
```shell
Expand Down
Loading