原生映像檔建置概觀
native-image
命令的語法為
native-image [options] <mainclass> [imagename] [options]
從目前工作目錄中的主類別建置原生二進位檔。類別路徑可選擇性地使用-cp <classpath>
選項提供,其中<classpath>
是目錄和 JAR 檔的路徑清單,以冒號分隔(在 Windows 上以分號分隔)。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
工具,請參閱建置組態。
原生映像檔在建置原生二進位檔時會輸出進度和各種統計資料。若要深入了解輸出和不同的建置階段,請參閱建置輸出。
如需有關建置程序、其階段和產生的原生二進位檔內容的詳細資訊,請參閱建置報告。