This document will show you how to access GraalVM with a dubbo project and how to compile the project to a binary executable using native-image.

For more information about GraalVM, read https://www.graalvm.org/docs/getting-started/container-images/.


Before compiling the dubbo project, make sure that we are programming based on the GraalVM environment.

  1. Install GraalVM

    Visite the official website (https://www.graalvm.org/ ) and install the latest version based on your system:


After installation, configure the path of JAVA_HOME. You should see thr following in your local jdk after this step:


GraalVM we use here is based on jdk version 1.8. To install native-image, run ‘gu install native-image’.

  1. Pull dubbo code and switch to branch apache:3.0.

  2. Manually generate SPI code

    Currently native-image compiling does not support dynamic code generation. Therefore we need to first manually generate the part of the code that is generated dynamically. The tool function is provided here:


Execute CodeGenerator can generate SPI code under the dubbo-native module.

  1. Execute ‘install’ under the root directory

    MacdeMacBook-pro-3:incubator-dubbo mac$ pwd
    MacdeMacBook-pro-3:incubator-dubbo mac$ mvn clean package install -Dmaven.test.skip=true
  2. Compile the project demo

    Here we provide a demo project that can be directly compiled: dubbo-demo / dubbo-demo-native. After installation, first go to the provider in dubbo-demo-native and execute native-image compilation:

     mvn clean package -P native -Dmaven.test.skip=true

    Since we have imported native-image plugin in maven, here we can use ‘-P native’ to execute the plugin.


After a success compilation, we can find the generated binary file under target. Succefully iniate a zookeeper locally and execute the binary executable file should show us this:


Compile on consumer’ side will generate a binary executable file ‘demo-native-consumer’ under consumer’s target. Execute the file will give us the following output:


Additional Steps

In this demo, we did extra work to make sure the project can be compiled. Here are the additional steps:

  • Import dependency dubbo-native


    Our generated SPI code is in this module.

  • Import native-image plug-in


    Generated image names and parameters used for generating image are defined.

  • Mount native-image-agent

    Since some classes, including reflection and JNI, need to be assigned, we have to use the agent to run the json information that generate these classes.

    Add the following to startup parameters:


    Launch in conventional way, create folder ‘META-INF.native-image’ under the resources folder and paste the generated files in the local directory into the folder.


(Missing classes’ information may exist. These information need to be manually added according to the error message reported while compiling or running.)

Finished the steps above, now you can compile your project.

Last modified February 23, 2023: Update for seo / img alt (35090e3f9b4)