配置mx
$ git clone https://github.com/graalvm/mx.git
$ export PATH=$PWD/mx:$PATH # 最好是配置到环境中
配置jdk
$ 下载对应的jdk
# 需要是graalvm官方提供的包,下载地址:
# https://github.com/graalvm/labs-openjdk/releases/tag/22%2B26-jvmci-b01
#配置环境变量
$ export JAVA_HOME=/usr/lib/jvm/oraclejdk1.8.0_212-jvmci-20-b01
$ export EXTRA_JAVA_HOMES=/usr/lib/jvm/jdk-11
下载源码
$ git clone https://github.com/oracle/graal.git
$ cd graal/vm
# libgraal是一个配置文件,具体路径在:vm/mx.vm/libgraal
$ mx --env libgraal build
$ mx --env libgraal graalvm-home #获取native-image
$ cd 找到的路径/Contents/Home/bin
# 这是我的路径:graal/sdk/mxbuild/darwin-aarch64/GRAALVM_6723241A54_JAVA22_STAGE1/graalvm-6723241a54-java22-24.0.0-dev/Contents/Home/bin
编译java代码
$ touch HelloWorld.java
$ vim HelloWorld.java #参考下面的demo,或者随便写一个最简单的demo
$ javac HelloWorld.java
$ ./native-image HelloWorld
$ ./HelloWorld
$ 控制台输出 Hello, World!
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
官方说明文档:
https://github.com/oracle/graal/tree/master/compiler
https://www.graalvm.org/community/contributors/