This is a "Hello Graal" Java example for GraalVM. The structure of the Hello
package is like this:
.
| src
| `--com/
| `-- hello
| `-- Graal.java
|-- LICENSE
|-- .gitignore
|-- manifest.txt
`-- README.md
-
Download and install GraalVM. You can download the latest GraalVM here.
-
Put GraalVM on the
PATH
:
export PATH=path/to/graal/bin:$PATH
java -version
On Oracle Linux or Red Hat:
sudo yum -y install graalvm22-ee-<11 or 17>-<version>.el7.x86_64
sudo yum -y install graalvm22-ee-<11 or 17-native-image
java -version
On a Debian based Linux machine:
export GRAAL_ZIP=graalvm-ce-java<11 or 17-linux-amd64-<version>.tar.gz
wget https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-<version>/$GRAAL_ZIP
tar -zxvf $GRAAL_ZIP
rm $GRAAL_ZIP
export PATH=/root/graalvm-ce-java<11 or 17-<version>/bin:$PATH
java -version
gu install native-image
- Download or clone the repository and navigate into the
functionGraphDemo
directory:
git clone https://github.com/graalvm/graalvm-demos
cd HelloGraal
- Compile the application running the follow command:
javac -d build src/com/hello/Graal.java
This generates the Graal.class
file into build/com/hello
directory.
- Run the application from a class file:
java -cp ./build com.hello.Graal
It outputs the message "hello graal".
- reate a JAR for the application, running the follow command:
jar cfvm Hello.jar manifest.txt -C build .
jar tf Hello.jar
The output will be:
META-INF/
META-INF/MANIFEST.MF
com/
com/hello/
com/hello/Graal.class
- Run the JAR file:
java -jar Hello.jar
It outputs the message "hello graal".
- Create a native executable of a JAR file:
native-image -jar Hello.jar
The executable called ./Hello
will be created in the working directory.
- Execute it:
./Hello
It outputs the message "hello graal".
To check the filesize of the executable image, run: ls -lh Hello
.