Skip to content

Instantly share code, notes, and snippets.

@renepanke
Created November 6, 2022 09:50
Show Gist options
  • Save renepanke/0354179a7dde85de2daee4187c68e193 to your computer and use it in GitHub Desktop.
Save renepanke/0354179a7dde85de2daee4187c68e193 to your computer and use it in GitHub Desktop.
Guide to create a native image from a Java Maven project

Guide to create a native image from a Java Maven project

Prerequisites

  • GraalVM installed as JDK
  • Native Image installed via gu
  • Single jar file project

Guide

  1. Create a new maven project
  2. Add the maven assembly plugin and configure it to produce a single jar file with dependencies. For an example see Maven Single Jar Example
  3. Execute mvn package to produce the jar file with dependencies
  4. Execute java -jar [PROJECT_NAME]-jar-with-dependencies.jar to see if your program is able to execute
  5. Execute `native-image -jar [PROJECT_NAME]-jar-with-dependencies.jar [TARGET_NATIVE_FILE_NAME]
  6. Execute ./[TARGET_NATIVE_FILE_NAME] to see if it is able to execute.
  7. Under Linux you can use time to see the actual execution time of both programs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment