Skip to content

Native Image with GraalVM

GraalVM Native Image compiles your Java application into a native executable. The jMonkeyEngine Native Image plugin helps prepare the classes, resources and native libraries needed by that executable.

For iOS, create your project with the Initializer. It sets up the build for you. See Debug, build and distribute for the commands.

Set up a desktop build

To use Native Image with a separate desktop Gradle project, install a GraalVM JDK with Native Image and the native compiler tools for your system. Then add the GraalVM and jMonkeyEngine plugins to your build.gradle:

plugins {
    id 'application'
    id 'org.graalvm.buildtools.native' version '<build-tools-version>'
    id 'org.jmonkeyengine.nativeimage' version '<jme-plugin-version>'
}

application {
    mainClass = 'com.example.MyGame'
}

jmeNativeImage {
    useDefaultResourceSettings()
}

Replace the version placeholders with compatible published versions and set mainClass to your application's main class. Build the executable with:

./gradlew nativeCompile

Include the assets and native libraries your game needs, and test the executable on your target system. Assets in a separate module may need additional resource configuration.

Classes used through reflection

The plugin automatically handles many engine classes. If your application uses one of your own classes through reflection, add the @PreserveReflection annotation to mark it for inclusion:

import com.jme3.util.PreserveReflection;

@PreserveReflection
public class MyController {
    public void startGame() {
        // Handle the UI action.
    }
}

For resource settings and other options, see the plugin documentation.