版本
- 适用于 JDK 24 的 GraalVM(最新)
- 适用于 JDK 25 的 GraalVM(早期访问)
- 适用于 JDK 21 的 GraalVM
- 适用于 JDK 17 的 GraalVM
- 存档
- 开发构建
Native Image 构建概览
native-image
命令的语法是
native-image [options] <mainclass> [imagename] [options]
用于从当前工作目录中的主类构建原生二进制文件。类路径可以通过-cp <classpath>
选项可选地提供,其中<classpath>
是一个冒号分隔(在 Windows 上是分号分隔)的目录和 JAR 文件路径列表。native-image [options] -jar jarfile [imagename] [options]
用于从 JAR 文件构建原生二进制文件。native-image [options] -m <module>/<mainClass> [imagename] [options]
用于从 Java 模块构建原生二进制文件。
传递给 native-image
的选项是从左到右评估的。有关可以传递给 native-image
的选项概述,请参阅此处。
构建过程完成时获取通知 #
根据应用程序的大小和构建机器的可用资源,将 Java 应用程序编译为原生可执行文件可能需要几分钟。如果您在后台构建应用程序,请考虑使用一个命令,在构建过程完成后通知您。下面列出了各个操作系统的示例命令
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
延伸阅读 #
如果您是 GraalVM Native Image 的新手或使用经验不足,请参阅Native Image 基础知识,以便在深入了解之前更好地理解一些关键方面。
有关更多调整以及如何正确配置 native-image
工具,请参阅构建配置。
Native Image 在构建原生二进制文件时会输出进度和各种统计信息。要了解有关输出和不同构建阶段的更多信息,请参阅构建输出。
有关构建过程、其阶段以及生成的原生二进制文件内容的更多详细信息,请参阅构建报告。