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 the latest GraalVM JDK using SDKMAN!.
sdk install java 21.0.1-graal
-
Download or clone GraalVM demos repository and navigate into the
hello-graal
directory:git clone https://github.com/graalvm/graalvm-demos
cd graalvm-demos/hello-graal
-
Compile the application running the follow command:
$JAVA_HOME/bin/javac -d build src/com/hello/Graal.java
This generates the
Graal.class
file intobuild/com/hello
directory. -
Run the application from a class file:
$JAVA_HOME/bin/java -cp ./build com.hello.Graal
It outputs the message "hello graal".
-
Create a JAR for the application, running the follow command:
$JAVA_HOME/bin/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_HOME/bin/java -jar Hello.jar
It outputs the message "hello graal".
-
Create a native executable of a JAR file:
$JAVA_HOME/bin/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
.