Search code examples
graalvmgraalvm-native-image

How to compile multiple JARs with GraalVM native image


All usage guides show how to run native-image on a single JAR file. But I believe most projects usually use multiple JARs on classpath (e.g. Gradle default way). How to tell native-image to bundle all of them into one executable?


Solution

  • You can specify the class path to use for building the executable:

    -cp, -classpath, --class-path <class search path of directories and zip/jar files>: a separated list of directories, JAR archives, and ZIP archives to search for class files.
    

    Here's more docs about various options to the native-image utility: https://www.graalvm.org/reference-manual/native-image/Options/

    All in all it should native-image -cp this.jar:that.jar -jar myjar.jar