How to build spring boot native binary

özkan pakdil - Oct 31 - - Dev Community

In short, I am explaining why we should use ./mvnw -Pnative native:compile and what error comes otherwise and why.

I was preparing this answer. And I was having problem with the class not found errors while building because I was using this command

./mvnw native:compile
...
Error: Please specify class (or <module>/<mainclass>) containing the main entry point method. (see --help)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.448 s
[INFO] Finished at: 2024-09-01T21:24:32+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.graalvm.buildtools:native-maven-plugin:0.10.2:compile (default-cli) on project env-variables: Execution of C:\sdkman\candidates\java\21.0.2-graal\bin\native-image.cmd @target\tmp\native-image-2373453772169200185.args returned non-zero result -> [Help 1]
[ERROR]

Enter fullscreen mode Exit fullscreen mode

Then remembered the profile thing and finally get rid of this error, used below command

./mvnw -Pnative native:compile

Enter fullscreen mode Exit fullscreen mode

that actually trigger spring-boot:process-aot that creates the required configuration for graalvm to build the project for native binary. Check this page for details.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player