First, I will like to say that I achieve this by following the tutorial from the from GraalVM and also reviewed some sample projects that they pushed out to help developers like us.
- Ensure you have GraalVM installed on your local computer. For me, I use a Mac and was able to install it using SDKMAN. SDKMAN is a useful tool for easy management of JDKs.
curl -s "https://get.sdkman.io" | bash
- Install GraalVM JDK:
sdk install java 17.0.9-graal && sdk use java 17.0.9-graal
At the point of writing this, I installed GraalVM support for java17. You can read the SDKMAN documentation to find more information on how you can install a specific version.
- Now that you have GraalVM installed, you are ready to start tinkering.
- Clone the project
git clone https://github.com/<project.git>
- CD into the project folder and compile the project to create a runnable JAR with all dependencies. Run in your terminal:
mvn clean package
- Run your application with the agent enabled:
mvn -Pnative -Dagent exec:exec@java-agent
The agent collects the metadata and generates the configuration files in a subdirectory of target/native/agent-output
. Those files will be automatically used by the native-image
tool if you pass the appropriate options.
- Now build a native executable with the Maven profile:
mvn -DskipTests=true -Pnative -Dagent package
When the command completes, a native executable, javalin-native
, is created in the /target
directory of the project and ready for use.
- Run the executable directly or with the Maven profile:
./target/javalin-native
| mvn -Pnative exec:exec@native
- Run tests on building native executable file
Kindly create a PR for any error fixes, improvements and updates.