From 720f59dd03cc28261775a9221abe2ff7a8279b25 Mon Sep 17 00:00:00 2001
From: Web Publisher The We provide Maven and Gradle plugins for Native Image to automate building, testing, and configuring native executables. The Maven plugin for Native Image adds support for compiling a Java application into a native executable using Apache Maven. For example, you can run this command to create a new Maven project using the quickstart archetype: Set the The native executable, named That is it, you successfully created the native executable for your Java application using Maven. The Maven plugin for Native Image building offers many other features that may be required for an application with more complexity, such as resources autodetection, generating the required configuration, running JUnit Platform tests on a native executable, and so on, described in the plugin reference documentation. The Gradle plugin for Native Image adds support for compiling a Java application into a native executable using the Gradle build tool. For example, initialize a new Gradle project with the Follow the prompts.
+ This command sets up a new Java application with the necessary directory structure and build files. Specify the latest plugin version for the The native executable, named That is it, you successfully created the native executable for your Java application using Gradle. The Gradle plugin for Native Image building has many other features that may be required for an application with more complexity, such as resources autodetection, generating the required configuration, running JUnit Platform tests on a native executable, and so on, described in the plugin reference documentation. The To build a native executable from a Java class file in the current working directory, use the following command: For more information about how to produce a native executable from a modular Java application, see Building a HelloWorld Java Module into a Native Executable. Depending on the size of your application and the available resources of your build machine, it can take a few minutes to AOT-compile your Java application to a native executable.
-If you are building your project in the background, consider using a command that notifies you when the build process is completed.
-Below, example commands are listed per operating system: There many options you can pass to the There many options you can pass to the For different build tweaks and to learn more about build time configuration, see Native Image Build Configuration. Native Image will output the progress and various statistics during the build. To learn more about the output and the different build phases, see Build Output. Native Image will output the progress and various statistics during the build.
+To learn more about the output and the different build phases, see Build Output. For more complex applications that use external libraries, you must provide the For more complex applications that use external libraries, you must provide the Building a standalone binary with the Building a standalone binary with Search Results
"latest-reference-manual-native-image-overview-build-overview": {
"title": "Native Image Build Overview",
- "content": "Native Image Build OverviewThe syntax of the native-image command is: native-image [options] <mainclass> [imagename] [options] to build a native binary from the main class in the current working directory. The classpath may optionally be provided with the -cp <classpath> option where <classpath> is a colon-separated (on Windows, semicolon-separated) list of paths to directories and JAR files. native-image [options] -jar jarfile [imagename] [options] to build a native binary from a JAR file. native-image [options] -m <module>/<mainClass> [imagename] [options] to build a native binary from a Java module.The options passed to native-image are evaluated from left to right.For an overview of options that can be passed to native-image, see here.Further ReadingIf you are new to GraalVM Native Image or have little experience using it, see the Native Image Basics to better understand some key aspects before going further.For more tweaks and how to properly configure the native-image tool, see Build Configuration.Native Image outputs the progress and various statistics when building a native binary. To learn more about the output, and the different build phases, see Build Output.",
+ "content": "Native Image Build OverviewThe syntax of the native-image command is: native-image [options] <mainclass> [imagename] [options] to build a native binary from the main class in the current working directory. The classpath may optionally be provided with the -cp <classpath> option where <classpath> is a colon-separated (on Windows, semicolon-separated) list of paths to directories and JAR files. native-image [options] -jar jarfile [imagename] [options] to build a native binary from a JAR file. native-image [options] -m <module>/<mainClass> [imagename] [options] to build a native binary from a Java module.The options passed to native-image are evaluated from left to right.For an overview of options that can be passed to native-image, see here.Getting Notified When the Build Process Is DoneDepending on the size of your application and the available resources of your build machine, it can take a few minutes to compile your Java application into a native executable.If you are building your application in the background, consider using a command that notifies you when the build process is completed.Below, example commands are listed per operating system:Linux# Ring the terminal bellnative-image -jar App.jar ... ; printf 'a'# Use libnotify to create a desktop notificationnative-image -jar App.jar ... ; notify-send "GraalVM Native Image build completed with exit code $?"# Use Zenity to open an info dialog box with textnative-image -jar App.jar ... ; zenity --info --text="GraalVM Native Image build completed with exit code $?"macOS# Ring the terminal bellnative-image -jar App.jar ... ; printf 'a'# Use Speech Synthesisnative-image -jar App.jar ... ; say "GraalVM Native Image build completed"Windows# Ring the terminal bell (press Ctrl+G to enter ^G)native-image.exe -jar App.jar & echo ^G# Open an info dialog box with textnative-image.exe -jar App.jar & msg "%username%" GraalVM Native Image build completedFurther ReadingIf you are new to GraalVM Native Image or have little experience using it, see the Native Image Basics to better understand some key aspects before going further.For more tweaks and how to properly configure the native-image tool, see Build Configuration.Native Image outputs the progress and various statistics when building a native binary. To learn more about the output, and the different build phases, see Build Output.",
"url": " /latest/reference-manual/native-image/overview/Build-Overview/"
},
@@ -1106,7 +1106,7 @@ Search Results
"latest-reference-manual-native-image": {
"title": "Native Image",
- "content": "Native ImageNative Image is a technology to compile Java code ahead-of-time to a binary – a native executable. A native executable includes only the code required at run time, that is the application classes, standard-library classes, the language runtime, and statically-linked native code from the JDK.An executable file produced by Native Image has several important advantages, in that it Uses a fraction of the resources required by the Java Virtual Machine, so is cheaper to run Starts in milliseconds Delivers peak performance immediately, with no warmup Can be packaged into a lightweight container image for fast and efficient deployment Presents a reduced attack surfaceA native executable is created by the Native Image builder or native-image that processes your application classes and other metadata to create a binary for a specific operating system and architecture.First, the native-image tool performs static analysis of your code to determine the classes and methods that are reachable when your application runs.Second, it compiles classes, methods, and resources into a binary.This entire process is called build time to clearly distinguish it from the compilation of Java source code to bytecode.The native-image tool can be used to build a native executable, which is the default, or a native shared library. This quick start guide focuses on building a native executable; to learn more about native shared libraries, go here.To get used to Native Image terminology and get better understanding of the technology, we recommend you to read the Basics of Native Image.Table of Contents Build a Native Executable Configuring Native Image with Third-Party Libraries Further ReadingPrerequisitesThe native-image tool, available in the bin directory of your GraalVM installation, depends on the local toolchain (header files for the C library, glibc-devel, zlib, gcc, and/or libstdc++-static). These dependencies can be installed (if not yet installed) using a package manager on your machine.Choose your operating system to find instructions to meet the prerequisites. // BEGIN-SNIPPETOn Oracle Linux use the YUM package manager:```shell$ sudo yum install gcc glibc-devel zlib-devel```Some Linux distributions may additionally require libstdc++-static.You can install libstdc++-static if the optional repositories are enabled (_ol7_optional_latest_ on Oracle Linux 7 and _ol8_codeready_builder_ on Oracle Linux 8).On Ubuntu Linux use the `apt-get` package manager:$ sudo apt-get install build-essential zlib1g-devOn other Linux distributions use the DNF package manager:$ sudo dnf install gcc glibc-devel zlib-devel libstdc++-static// END-SNIPPET // BEGIN-SNIPPETOn macOS use Xcode:$ xcode-select --install// END-SNIPPET // BEGIN-SNIPPETTo use Native Image on Windows, install Visual Studio 2022 version 17.6.0 or later, and Microsoft Visual C++ (MSVC). There are two installation options:* Install the Visual Studio Build Tools with the Windows 11 SDK (or later version)* Install Visual Studio with the Windows 11 SDK (or later version)Native Image runs in both a PowerShell or Command Prompt and will automatically set up build environments on Windows, given that it can find a suitable Visual Studio installation.// END-SNIPPET Linux macOS Windows Build a Native ExecutableThe native-image tool takes Java bytecode as its input. You can build a native executable from a class file, from a JAR file, or from a module (with Java 9 and higher).From a ClassTo build a native executable from a Java class file in the current working directory, use the following command:native-image [options] class [imagename] [options]For example, build a native executable for a HelloWorld application. Save this code into file named HelloWorld.java: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, Native World!"); } } Compile it and build a native executable from the Java class: javac HelloWorld.java native-image HelloWorld It will create a native executable, helloworld, in the current working directory. Run the application: ./helloworld You can time it to see the resources used: time -f 'Elapsed Time: %e s Max RSS: %M KB' ./helloworld # Hello, Native World! # Elapsed Time: 0.00 s Max RSS: 7620 KB From a JAR fileTo build a native executable from a JAR file in the current working directory, use the following command:native-image [options] -jar jarfile [imagename]The default behavior of native-image is aligned with the java command which means you can pass the -jar, -cp, -m options to build with Native Image as you would normally do with java. For example, java -jar App.jar someArgument becomes native-image -jar App.jar and ./App someArgument.Follow this guide to build a native executable from a JAR file.From a ModuleYou can also convert a modularized Java application into a native executable.The command to build a native executable from a Java module is:native-image [options] --module <module>[/<mainclass>] [options]For more information about how to produce a native executable from a modular Java application, see Building a HelloWorld Java Module into a Native Executable.Getting Notified When the Build Process Is DoneDepending on the size of your application and the available resources of your build machine, it can take a few minutes to AOT-compile your Java application to a native executable.If you are building your project in the background, consider using a command that notifies you when the build process is completed.Below, example commands are listed per operating system:Linux# Ring the terminal bellnative-image -jar App.jar ... ; printf 'a'# Use libnotify to create a desktop notificationnative-image -jar App.jar ... ; notify-send "GraalVM Native Image build completed with exit code $?"# Use Zenity to open an info dialog box with textnative-image -jar App.jar ... ; zenity --info --text="GraalVM Native Image build completed with exit code $?"macOS# Ring the terminal bellnative-image -jar App.jar ... ; printf 'a'# Use Speech Synthesisnative-image -jar App.jar ... ; say "GraalVM Native Image build completed"Windows# Ring the terminal bell (press Ctrl+G to enter ^G)native-image.exe -jar App.jar & echo ^G# Open an info dialog box with textnative-image.exe -jar App.jar & msg "%username%" GraalVM Native Image build completedBuild ConfigurationThere many options you can pass to the native-image builder to configure the build process. Run native-image --help to see the full list.The options passed to native-image are evaluated left-to-right.For different build tweaks and to learn more about build time configuration, see Native Image Build Configuration.Native Image will output the progress and various statistics during the build. To learn more about the output and the different build phases, see Build Output.Native Image and Third-Party LibrariesFor more complex applications that use external libraries, you must provide the native-image builder with metadata.Building a standalone binary with the native-image tool takes place under a “closed world assumption”. The native-image tool performs an analysis to see which classes, methods, and fields within your application are reachable and must be included in the native image. The analysis is static: it does not run your application.This means that all the bytecode in your application that can be called at run time must be known (observed and analyzed) at build time.The analysis can determine some cases of dynamic class loading, but it cannot always exhaustively predict all usages of the Java Native Interface (JNI), Java Reflection, Dynamic Proxy objects, or class path resources. To deal with these dynamic features of Java, you inform the analysis with details of the classes that use Reflection, Proxy, and so on, or what classes to be dynamically loaded.To achieve this, you either provide the native-image tool with JSON-formatted configuration files or pre-compute metadata in the code.To learn more about metadata, ways to provide it, and supported metadata types, see Reachability Metadata.To automatically collect metadata for your application, see Automatic Collection of Metadata.There are also Maven and Gradle plugins for Native Image to automate building, testing and configuring native executables. Learn more here.Some applications may need additional configuration to be compiled with GraalVM Native Image.For more details, see Native Image Compatibility Guide.Native Image can also interop with native languages through a custom API.Using this API, you can specify custom native entry points into your Java application and build it into a nativw shared library.To learn more, see Interoperability with Native Code.Further ReadingThis getting started guide is intended for new users or those with little experience of using GraalVM Native Image. We strongly recommend these users to check the Basics of Native Image page to better understand some key aspects before going deeper.Check user guides to become more experienced with GraalVM Native Image, find demo examples, and learn about potential usage scenarios.For a gradual learning process, check the Native Image Build Overview and Build Configuration documentation.Consider running interactive workshops to get some practical experience: go to Luna Labs and search for “Native Image”.If you have stumbled across a potential bug, please submit an issue in GitHub.If you would like to contribute to Native Image, follow our standard contributing workflow.",
+ "content": "Native ImageNative Image is a technology to compile Java code ahead-of-time to a binary – a native executable. A native executable includes only the code required at run time, that is the application classes, standard-library classes, the language runtime, and statically-linked native code from the JDK.An executable file produced by Native Image has several important advantages, in that it Uses a fraction of the resources required by the Java Virtual Machine, so is cheaper to run Starts in milliseconds Delivers peak performance immediately, with no warmup Can be packaged into a lightweight container image for fast and efficient deployment Presents a reduced attack surfaceA native executable is created by the Native Image builder or native-image that processes your application classes and other metadata to create a binary for a specific operating system and architecture.First, the native-image tool performs static analysis of your code to determine the classes and methods that are reachable when your application runs.Second, it compiles classes, methods, and resources into a binary.This entire process is called build time to clearly distinguish it from the compilation of Java source code to bytecode.The native-image tool can be used to build a native executable, which is the default, or a native shared library. This quick start guide focuses on building a native executable; to learn more about native shared libraries, go here.To get used to Native Image terminology and get better understanding of the technology, we recommend you to read the Basics of Native Image.Table of Contents Build a Native Executable Using Maven or Gradle Build a Native Executable Using the native-image Tool Build Configuration Configuring Native Image with Third-Party Libraries Further ReadingPrerequisitesThe native-image tool, available in the bin directory of your GraalVM installation, depends on the local toolchain (header files for the C library, glibc-devel, zlib, gcc, and/or libstdc++-static). These dependencies can be installed (if not yet installed) using a package manager on your machine.Choose your operating system to find instructions to meet the prerequisites. // BEGIN-SNIPPETOn Oracle Linux use the YUM package manager:```shell$ sudo yum install gcc glibc-devel zlib-devel```Some Linux distributions may additionally require libstdc++-static.You can install libstdc++-static if the optional repositories are enabled (_ol7_optional_latest_ on Oracle Linux 7 and _ol8_codeready_builder_ on Oracle Linux 8).On Ubuntu Linux use the `apt-get` package manager:$ sudo apt-get install build-essential zlib1g-devOn other Linux distributions use the DNF package manager:$ sudo dnf install gcc glibc-devel zlib-devel libstdc++-static// END-SNIPPET // BEGIN-SNIPPETOn macOS use Xcode:$ xcode-select --install// END-SNIPPET // BEGIN-SNIPPETTo use Native Image on Windows, install Visual Studio 2022 version 17.6.0 or later, and Microsoft Visual C++ (MSVC). There are two installation options:* Install the Visual Studio Build Tools with the Windows 11 SDK (or later version)* Install Visual Studio with the Windows 11 SDK (or later version)Native Image runs in both a PowerShell or Command Prompt and will automatically set up build environments on Windows, given that it can find a suitable Visual Studio installation.// END-SNIPPET Linux macOS Windows Build a Native Executable Using Maven or GradleWe provide Maven and Gradle plugins for Native Image to automate building, testing, and configuring native executables.MavenThe Maven plugin for Native Image adds support for compiling a Java application into a native executable using Apache Maven. Create a new Maven Java project named “helloworld” in your favorite IDE or from your terminal with the following structure: ├── pom.xml └── src ├── main │ └── java │ └── com │ └── example │ └── App.java For example, you can run this command to create a new Maven project using the quickstart archetype: mvn archetype:generate -DgroupId=com.example -DartifactId=helloworld -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false Add the regular Maven plugins for compiling and assembling the project into an executable JAR file to your pom.xml file: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.12.1</version> <configuration> <fork>true</fork> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.3.0</version> <configuration> <archive> <manifest> <mainClass>com.example.App</mainClass> <addClasspath>true</addClasspath> </manifest> </archive> </configuration> </plugin> </plugins> </build> Enable the Maven plugin for Native Image by adding the following profile to pom.xml: <profiles> <profile> <id>native</id> <build> <plugins> <plugin> <groupId>org.graalvm.buildtools</groupId> <artifactId>native-maven-plugin</artifactId> <version>${native.maven.plugin.version}</version> <extensions>true</extensions> <executions> <execution> <id>build-native</id> <goals> <goal>compile-no-fork</goal> </goals> <phase>package</phase> </execution> <execution> <id>test-native</id> <goals> <goal>test</goal> </goals> <phase>test</phase> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles> Set the version property to the latest plugin version (for example, by specifying the version via <native.maven.plugin.version> in the <properties> element). Compile the project and build a native executable at one step: mvn -Pnative package The native executable, named helloworld, is created in the target/ directory of the project. Run the executable: ./target/helloworld That is it, you successfully created the native executable for your Java application using Maven. The Maven plugin for Native Image building offers many other features that may be required for an application with more complexity, such as resources autodetection, generating the required configuration, running JUnit Platform tests on a native executable, and so on, described in the plugin reference documentation.GradleThe Gradle plugin for Native Image adds support for compiling a Java application into a native executable using the Gradle build tool. Create a new Gradle Java project named “helloworld” in your favorite IDE or from your terminal with the following structure: ├── app │ ├── build.gradle │ └── src │ ├── main │ │ ├── java │ │ │ └── org │ │ │ └── example │ │ │ └── App.java │ │ └── resources For example, initialize a new Gradle project with the java plugin: Create a new directory and enter it: mkdir helloworld && cd helloworld Generate a project: gradle init --project-name helloworld --type java-application --test-framework junit-jupiter --dsl groovy Follow the prompts. This command sets up a new Java application with the necessary directory structure and build files. Enable the Gradle plugin for Native Image by adding the following to plugins section of your project’s build.gradle file: plugins { // ... id 'org.graalvm.buildtools.native' version 'x.x.x' } Specify the latest plugin version for the 'x.x.x' version value. Build a native executable by running ./gradlew nativeCompile: ./gradlew nativeCompile The native executable, named app, is created in the app/build/native/nativeCompile/ directory of the project. Run the native executable: ./app/build/native/nativeCompile/app That is it, you successfully created the native executable for your Java application using Gradle. The Gradle plugin for Native Image building has many other features that may be required for an application with more complexity, such as resources autodetection, generating the required configuration, running JUnit Platform tests on a native executable, and so on, described in the plugin reference documentation.Build a Native Executable Using the native-image ToolThe native-image tool takes Java bytecode as its input. You can build a native executable from a class file, from a JAR file, or from a module (with Java 9 and higher).From a ClassTo build a native executable from a Java class file in the current working directory, use the following command:native-image [options] class [imagename] [options]For example, build a native executable for a HelloWorld application. Save this code into file named HelloWorld.java: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, Native World!"); } } Compile it and build a native executable from the Java class: javac HelloWorld.java native-image HelloWorld It will create a native executable, helloworld, in the current working directory. Run the application: ./helloworld You can time it to see the resources used: time -f 'Elapsed Time: %e s Max RSS: %M KB' ./helloworld # Hello, Native World! # Elapsed Time: 0.00 s Max RSS: 7620 KB From a JAR fileTo build a native executable from a JAR file in the current working directory, use the following command:native-image [options] -jar jarfile [imagename]The default behavior of native-image is aligned with the java command which means you can pass the -jar, -cp, -m options to build with Native Image as you would normally do with java. For example, java -jar App.jar someArgument becomes native-image -jar App.jar and ./App someArgument.Follow this guide to build a native executable from a JAR file.From a ModuleYou can also convert a modularized Java application into a native executable.The command to build a native executable from a Java module is:native-image [options] --module <module>[/<mainclass>] [options]For more information about how to produce a native executable from a modular Java application, see Building a HelloWorld Java Module into a Native Executable.Build ConfigurationThere many options you can pass to the native-image tool to configure the build process. Run native-image --help to see the full list.The options passed to native-image are evaluated left-to-right.For different build tweaks and to learn more about build time configuration, see Native Image Build Configuration.Native Image will output the progress and various statistics during the build. To learn more about the output and the different build phases, see Build Output.Native Image and Third-Party LibrariesFor more complex applications that use external libraries, you must provide the native-image tool with metadata.Building a standalone binary with native-image takes place under a “closed world assumption”. The native-image tool performs an analysis to see which classes, methods, and fields within your application are reachable and must be included in the native executable. The analysis is static: it does not run your application.This means that all the bytecode in your application that can be called at runtime must be known (observed and analyzed) at build time.The analysis can determine some cases of dynamic class loading, but it cannot always exhaustively predict all usages of the Java Native Interface (JNI), Java Reflection, Dynamic Proxy objects, or class path resources. To deal with these dynamic features of Java, you inform the analysis with details of the classes that use Reflection, Proxy, and so on, or what classes to be dynamically loaded.To achieve this, you either provide the native-image tool with JSON-formatted configuration files or pre-compute metadata in the code.To learn more about metadata, ways to provide it, and supported metadata types, see Reachability Metadata.To automatically collect metadata for your application, see Automatic Collection of Metadata.Some applications may need additional configuration to be compiled with Native Image.For more details, see Native Image Compatibility Guide.Native Image can also interop with native languages through a custom API.Using this API, you can specify custom native entry points into your Java application and build it into a native shared library.To learn more, see Interoperability with Native Code.Further ReadingThis getting started guide is intended for new users or those with little experience of using Native Image. We strongly recommend these users to check the Basics of Native Image page to better understand some key aspects before going deeper.Check user guides to become more experienced with Native Image, find demo examples, and learn about potential usage scenarios.For a gradual learning process, check the Native Image Build Overview and Build Configuration documentation.Consider running interactive workshops to get some practical experience: go to Luna Labs and search for “Native Image”.If you have stumbled across a potential bug, please submit an issue in GitHub.If you would like to contribute to Native Image, follow our standard contributing workflow.",
"url": " /latest/reference-manual/native-image/"
},
diff --git a/jdk17/reference-manual/ruby/index.html b/jdk17/reference-manual/ruby/index.html
index 83b4bdb7efc00..32666ffcbb615 100644
--- a/jdk17/reference-manual/ruby/index.html
+++ b/jdk17/reference-manual/ruby/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/jdk21/reference-manual/ruby/index.html b/jdk21/reference-manual/ruby/index.html
index 901938c1e5cdd..846a7bef405a8 100644
--- a/jdk21/reference-manual/ruby/index.html
+++ b/jdk21/reference-manual/ruby/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/jdk22/reference-manual/native-image/index.html b/jdk22/reference-manual/native-image/index.html
index 044d4b8073b3c..3b18061efb442 100644
--- a/jdk22/reference-manual/native-image/index.html
+++ b/jdk22/reference-manual/native-image/index.html
@@ -13,7 +13,7 @@
-
+
@@ -558,7 +558,9 @@
-
@@ -787,15 +789,186 @@ native-image
Tool
For more information, see [Using GraalVM and Native Image on Windows](https://medium.com/graalvm/using-graalvm-and-native-image-on-windows-10-9954dc071311). -->
-
+
- Build a Native Executable #
+ Build a Native Executable Using Maven or Gradle #
-native-image
tool takes Java bytecode as its input. You can build a native executable from a class file, from a JAR file, or from a module (with Java 9 and higher).
+
+
+ Maven #
+
+
+
+
+
+
+
+
+ ├── pom.xml
+ └── src
+ ├── main
+ │ └── java
+ │ └── com
+ │ └── example
+ │ └── App.java
+
+ mvn archetype:generate -DgroupId=com.example -DartifactId=helloworld -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.12.1</version>
+ <configuration>
+ <fork>true</fork>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.3.0</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>com.example.App</mainClass>
+ <addClasspath>true</addClasspath>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>native</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.graalvm.buildtools</groupId>
+ <artifactId>native-maven-plugin</artifactId>
+ <version>${native.maven.plugin.version}</version>
+ <extensions>true</extensions>
+ <executions>
+ <execution>
+ <id>build-native</id>
+ <goals>
+ <goal>compile-no-fork</goal>
+ </goals>
+ <phase>package</phase>
+ </execution>
+ <execution>
+ <id>test-native</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <phase>test</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
version
property to the latest plugin version (for example, by specifying the version via <native.maven.plugin.version>
in the <properties>
element).
+ mvn -Pnative package
+
helloworld
, is created in the target/ directory of the project.
+ ./target/helloworld
+
+
+
+ Gradle #
+
+
+
+
+
+
+
+
+
+ ├── app
+ │ ├── build.gradle
+ │ └── src
+ │ ├── main
+ │ │ ├── java
+ │ │ │ └── org
+ │ │ │ └── example
+ │ │ │ └── App.java
+ │ │ └── resources
+
java
plugin:
+
+
+ mkdir helloworld && cd helloworld
+
+ gradle init --project-name helloworld --type java-application --test-framework junit-jupiter --dsl groovy
+
plugins
section of your project’s build.gradle file:
+
+ plugins {
+ // ...
+ id 'org.graalvm.buildtools.native' version 'x.x.x'
+ }
+
'x.x.x'
version value../gradlew nativeCompile
:
+
+ ./gradlew nativeCompile
+
app
, is created in the app/build/native/nativeCompile/ directory of the project.
+ ./app/build/native/nativeCompile/app
+
+
+
+ Build a Native Executable Using the
+
+native-image
Tool #
+
+
+ native-image
tool takes Java bytecode as its input.
+You can build a native executable from a class file, from a JAR file, or from a module (with Java 9 and higher).
@@ -804,6 +977,7 @@
+
@@ -871,63 +1045,6 @@ native-image [options] class [imagename] [options]
-
-
- Getting Notified When the Build Process Is Done #
-
-
-
-
-
-
-
- Linux
-
-
-
-
-
- # Ring the terminal bell
-native-image -jar App.jar ... ; printf '\a'
-
-# Use libnotify to create a desktop notification
-native-image -jar App.jar ... ; notify-send "GraalVM Native Image build completed with exit code $?"
-
-# Use Zenity to open an info dialog box with text
-native-image -jar App.jar ... ; zenity --info --text="GraalVM Native Image build completed with exit code $?"
-
-
-
- macOS
-
-
-
-
-
- # Ring the terminal bell
-native-image -jar App.jar ... ; printf '\a'
-
-# Use Speech Synthesis
-native-image -jar App.jar ... ; say "GraalVM Native Image build completed"
-
-
-
- Windows
-
-
-
-
-
# Ring the terminal bell (press Ctrl+G to enter ^G)
-native-image.exe -jar App.jar & echo ^G
-
-# Open an info dialog box with text
-native-image.exe -jar App.jar & msg "%username%" GraalVM Native Image build completed
-
@@ -936,12 +1053,14 @@
-native-image
builder to configure the build process. Run native-image --help
to see the full list.
+native-image
tool to configure the build process.
+Run native-image --help
to see the full list.
The options passed to native-image
are evaluated left-to-right.
@@ -951,12 +1070,12 @@
-native-image
builder with metadata.native-image
tool with metadata.native-image
tool takes place under a “closed world assumption”.
-The native-image
tool performs an analysis to see which classes, methods, and fields within your application are reachable and must be included in the native image.
+native-image
takes place under a “closed world assumption”.
+The native-image
tool performs an analysis to see which classes, methods, and fields within your application are reachable and must be included in the native executable.
The analysis is static: it does not run your application.
-This means that all the bytecode in your application that can be called at run time must be known (observed and analyzed) at build time.
The analysis can determine some cases of dynamic class loading, but it cannot always exhaustively predict all usages of the Java Native Interface (JNI), Java Reflection, Dynamic Proxy objects, or class path resources. To deal with these dynamic features of Java, you inform the analysis with details of the classes that use Reflection, Proxy, and so on, or what classes to be dynamically loaded. @@ -965,13 +1084,11 @@
To learn more about metadata, ways to provide it, and supported metadata types, see Reachability Metadata. To automatically collect metadata for your application, see Automatic Collection of Metadata.
-There are also Maven and Gradle plugins for Native Image to automate building, testing and configuring native executables. Learn more here.
- -Some applications may need additional configuration to be compiled with GraalVM Native Image. +
Some applications may need additional configuration to be compiled with Native Image. For more details, see Native Image Compatibility Guide.
Native Image can also interop with native languages through a custom API. -Using this API, you can specify custom native entry points into your Java application and build it into a nativw shared library. +Using this API, you can specify custom native entry points into your Java application and build it into a native shared library. To learn more, see Interoperability with Native Code.
This getting started guide is intended for new users or those with little experience of using GraalVM Native Image. +
This getting started guide is intended for new users or those with little experience of using Native Image. We strongly recommend these users to check the Basics of Native Image page to better understand some key aspects before going deeper.
-Check user guides to become more experienced with GraalVM Native Image, find demo examples, and learn about potential usage scenarios.
+Check user guides to become more experienced with Native Image, find demo examples, and learn about potential usage scenarios.
For a gradual learning process, check the Native Image Build Overview and Build Configuration documentation.
diff --git a/jdk22/reference-manual/native-image/overview/Build-Overview/index.html b/jdk22/reference-manual/native-image/overview/Build-Overview/index.html index 128402e80d485..e2ec65b9580fe 100644 --- a/jdk22/reference-manual/native-image/overview/Build-Overview/index.html +++ b/jdk22/reference-manual/native-image/overview/Build-Overview/index.html @@ -13,7 +13,7 @@ - + @@ -581,6 +581,63 @@The options passed to native-image
are evaluated from left to right.
For an overview of options that can be passed to native-image
, see here.
Depending on the size of your application and the available resources of your build machine, it can take a few minutes to compile your Java application into a native executable. +If you are building your application in the background, consider using a command that notifies you when the build process is completed. +Below, example commands are listed per operating system:
+ +# Ring the terminal bell
+native-image -jar App.jar ... ; printf '\a'
+
+# Use libnotify to create a desktop notification
+native-image -jar App.jar ... ; notify-send "GraalVM Native Image build completed with exit code $?"
+
+# Use Zenity to open an info dialog box with text
+native-image -jar App.jar ... ; zenity --info --text="GraalVM Native Image build completed with exit code $?"
+
+
+ # Ring the terminal bell
+native-image -jar App.jar ... ; printf '\a'
+
+# Use Speech Synthesis
+native-image -jar App.jar ... ; say "GraalVM Native Image build completed"
+
+
+ # Ring the terminal bell (press Ctrl+G to enter ^G)
+native-image.exe -jar App.jar & echo ^G
+
+# Open an info dialog box with text
+native-image.exe -jar App.jar & msg "%username%" GraalVM Native Image build completed
+
+
native-image
ToolThe native-image
tool takes Java bytecode as its input. You can build a native executable from a class file, from a JAR file, or from a module (with Java 9 and higher).
We provide Maven and Gradle plugins for Native Image to automate building, testing, and configuring native executables.
+ +The Maven plugin for Native Image adds support for compiling a Java application into a native executable using Apache Maven.
+ + ├── pom.xml
+ └── src
+ ├── main
+ │ └── java
+ │ └── com
+ │ └── example
+ │ └── App.java
+
+ For example, you can run this command to create a new Maven project using the quickstart archetype:
+ mvn archetype:generate -DgroupId=com.example -DartifactId=helloworld -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.12.1</version>
+ <configuration>
+ <fork>true</fork>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.3.0</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>com.example.App</mainClass>
+ <addClasspath>true</addClasspath>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>native</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.graalvm.buildtools</groupId>
+ <artifactId>native-maven-plugin</artifactId>
+ <version>${native.maven.plugin.version}</version>
+ <extensions>true</extensions>
+ <executions>
+ <execution>
+ <id>build-native</id>
+ <goals>
+ <goal>compile-no-fork</goal>
+ </goals>
+ <phase>package</phase>
+ </execution>
+ <execution>
+ <id>test-native</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <phase>test</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+ Set the version
property to the latest plugin version (for example, by specifying the version via <native.maven.plugin.version>
in the <properties>
element).
mvn -Pnative package
+
+ The native executable, named helloworld
, is created in the target/ directory of the project.
./target/helloworld
+
+ That is it, you successfully created the native executable for your Java application using Maven.
+The Maven plugin for Native Image building offers many other features that may be required for an application with more complexity, such as resources autodetection, generating the required configuration, running JUnit Platform tests on a native executable, and so on, described in the plugin reference documentation.
+ +The Gradle plugin for Native Image adds support for compiling a Java application into a native executable using the Gradle build tool.
+ + ├── app
+ │ ├── build.gradle
+ │ └── src
+ │ ├── main
+ │ │ ├── java
+ │ │ │ └── org
+ │ │ │ └── example
+ │ │ │ └── App.java
+ │ │ └── resources
+
+
+ For example, initialize a new Gradle project with the java
plugin:
mkdir helloworld && cd helloworld
+
+ gradle init --project-name helloworld --type java-application --test-framework junit-jupiter --dsl groovy
+
+ Follow the prompts. + This command sets up a new Java application with the necessary directory structure and build files.
+plugins
section of your project’s build.gradle file:
+ plugins {
+ // ...
+ id 'org.graalvm.buildtools.native' version 'x.x.x'
+ }
+
+ Specify the latest plugin version for the 'x.x.x'
version value.
./gradlew nativeCompile
:
+ ./gradlew nativeCompile
+
+ The native executable, named app
, is created in the app/build/native/nativeCompile/ directory of the project.
./app/build/native/nativeCompile/app
+
+ That is it, you successfully created the native executable for your Java application using Gradle.
+The Gradle plugin for Native Image building has many other features that may be required for an application with more complexity, such as resources autodetection, generating the required configuration, running JUnit Platform tests on a native executable, and so on, described in the plugin reference documentation.
+ +native-image
Tool #
+
+
+ The native-image
tool takes Java bytecode as its input.
+You can build a native executable from a class file, from a JAR file, or from a module (with Java 9 and higher).
To build a native executable from a Java class file in the current working directory, use the following command:
native-image [options] class [imagename] [options]
@@ -871,63 +1045,6 @@ For more information about how to produce a native executable from a modular Java application, see Building a HelloWorld Java Module into a Native Executable.
-Depending on the size of your application and the available resources of your build machine, it can take a few minutes to AOT-compile your Java application to a native executable. -If you are building your project in the background, consider using a command that notifies you when the build process is completed. -Below, example commands are listed per operating system:
- -# Ring the terminal bell
-native-image -jar App.jar ... ; printf '\a'
-
-# Use libnotify to create a desktop notification
-native-image -jar App.jar ... ; notify-send "GraalVM Native Image build completed with exit code $?"
-
-# Use Zenity to open an info dialog box with text
-native-image -jar App.jar ... ; zenity --info --text="GraalVM Native Image build completed with exit code $?"
-
-
- # Ring the terminal bell
-native-image -jar App.jar ... ; printf '\a'
-
-# Use Speech Synthesis
-native-image -jar App.jar ... ; say "GraalVM Native Image build completed"
-
-
- # Ring the terminal bell (press Ctrl+G to enter ^G)
-native-image.exe -jar App.jar & echo ^G
-
-# Open an info dialog box with text
-native-image.exe -jar App.jar & msg "%username%" GraalVM Native Image build completed
-
-
There many options you can pass to the native-image
builder to configure the build process. Run native-image --help
to see the full list.
+
There many options you can pass to the native-image
tool to configure the build process.
+Run native-image --help
to see the full list.
The options passed to native-image
are evaluated left-to-right.
For different build tweaks and to learn more about build time configuration, see Native Image Build Configuration.
-Native Image will output the progress and various statistics during the build. To learn more about the output and the different build phases, see Build Output.
+Native Image will output the progress and various statistics during the build. +To learn more about the output and the different build phases, see Build Output.
For more complex applications that use external libraries, you must provide the native-image
builder with metadata.
For more complex applications that use external libraries, you must provide the native-image
tool with metadata.
Building a standalone binary with the native-image
tool takes place under a “closed world assumption”.
-The native-image
tool performs an analysis to see which classes, methods, and fields within your application are reachable and must be included in the native image.
+
Building a standalone binary with native-image
takes place under a “closed world assumption”.
+The native-image
tool performs an analysis to see which classes, methods, and fields within your application are reachable and must be included in the native executable.
The analysis is static: it does not run your application.
-This means that all the bytecode in your application that can be called at run time must be known (observed and analyzed) at build time.
The analysis can determine some cases of dynamic class loading, but it cannot always exhaustively predict all usages of the Java Native Interface (JNI), Java Reflection, Dynamic Proxy objects, or class path resources. To deal with these dynamic features of Java, you inform the analysis with details of the classes that use Reflection, Proxy, and so on, or what classes to be dynamically loaded. @@ -965,13 +1084,11 @@
To learn more about metadata, ways to provide it, and supported metadata types, see Reachability Metadata. To automatically collect metadata for your application, see Automatic Collection of Metadata.
-There are also Maven and Gradle plugins for Native Image to automate building, testing and configuring native executables. Learn more here.
- -Some applications may need additional configuration to be compiled with GraalVM Native Image. +
Some applications may need additional configuration to be compiled with Native Image. For more details, see Native Image Compatibility Guide.
Native Image can also interop with native languages through a custom API. -Using this API, you can specify custom native entry points into your Java application and build it into a nativw shared library. +Using this API, you can specify custom native entry points into your Java application and build it into a native shared library. To learn more, see Interoperability with Native Code.
This getting started guide is intended for new users or those with little experience of using GraalVM Native Image. +
This getting started guide is intended for new users or those with little experience of using Native Image. We strongly recommend these users to check the Basics of Native Image page to better understand some key aspects before going deeper.
-Check user guides to become more experienced with GraalVM Native Image, find demo examples, and learn about potential usage scenarios.
+Check user guides to become more experienced with Native Image, find demo examples, and learn about potential usage scenarios.
For a gradual learning process, check the Native Image Build Overview and Build Configuration documentation.
diff --git a/latest/reference-manual/native-image/overview/Build-Overview/index.html b/latest/reference-manual/native-image/overview/Build-Overview/index.html index 5a0b7caaa0400..c92ed5f308f36 100644 --- a/latest/reference-manual/native-image/overview/Build-Overview/index.html +++ b/latest/reference-manual/native-image/overview/Build-Overview/index.html @@ -13,7 +13,7 @@ - + @@ -581,6 +581,63 @@The options passed to native-image
are evaluated from left to right.
For an overview of options that can be passed to native-image
, see here.
Depending on the size of your application and the available resources of your build machine, it can take a few minutes to compile your Java application into a native executable. +If you are building your application in the background, consider using a command that notifies you when the build process is completed. +Below, example commands are listed per operating system:
+ +# Ring the terminal bell
+native-image -jar App.jar ... ; printf '\a'
+
+# Use libnotify to create a desktop notification
+native-image -jar App.jar ... ; notify-send "GraalVM Native Image build completed with exit code $?"
+
+# Use Zenity to open an info dialog box with text
+native-image -jar App.jar ... ; zenity --info --text="GraalVM Native Image build completed with exit code $?"
+
+
+ # Ring the terminal bell
+native-image -jar App.jar ... ; printf '\a'
+
+# Use Speech Synthesis
+native-image -jar App.jar ... ; say "GraalVM Native Image build completed"
+
+
+ # Ring the terminal bell (press Ctrl+G to enter ^G)
+native-image.exe -jar App.jar & echo ^G
+
+# Open an info dialog box with text
+native-image.exe -jar App.jar & msg "%username%" GraalVM Native Image build completed
+
+