GraalVM + Native-Image 的安装和使用

Mac
下载最新版 https://github.com/graalvm/graalvm-ce-builds/releases/tag/vm-21.3.0
把 graalvm 和 native-image都下载下来。
然后安装!

$ cd /opt/local/graalvm
$ tar -xzf *.tar.gz
$ export JAVA_HOME=/opt/local/graalvm/graalvm-ce-java17-21.3.0/Contents/Home
$ export oldPATH=$PATH
$ export PATH=$JAVA_HOME/bin:$PATH
$ gu install -L native-image*
$ javac HelloWorld.java
$ native-image HelloWorld
$ export PATH=$oldPATH

$ ./helloworld 
Hello World!

做一个快捷方式:

vi /usr/local/bin/native-image

oldJH=$JAVA_HOME
JAVA_HOME=/opt/local/graalvm/graalvm-ce-java17-21.3.0/Contents/Home
oldPath=$PATH
PATH=$JAVA_HOME/bin:$PATH
native-image $*
JAVA_HOME=$oldJH
PATH=$oldPATH

chmod +x /usr/local/bin/native-image

Now you can play it like: native-image HelloWorld!
Enjoy your game! cheers!

你可能感兴趣的:(GraalVM + Native-Image 的安装和使用)