原生镜像构建概述
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
工具,请参阅 构建配置.
原生镜像在构建原生二进制文件时输出进度和各种统计信息。要了解有关输出和不同构建阶段的更多信息,请参阅 构建输出.
有关构建过程、阶段和生成的原生二进制文件内容的更详细的信息,请参阅 构建报告.