The demo is a Java program that simulates the traditional fortune
Unix program (for more information, see fortune). The data for the fortune phrases is provided by YourFortune.
The Fortune demo is comprised of three sub-projects:
- The fortune-maven project uses the Maven plugin for GraalVM Native Image building.
- The fortune-gradle project uses the Gradle plugin for GraalVM Native Image building.
-
Download and install GraalVM. The easiest way for Linux/macOS is with SDKMAN!:
sdk install java <version>-graal
For other installation options, visit the Downloads section.
-
Download or clone the GraalVM demos repository:
git clone https://github.com/graalvm/graalvm-demos
-
Change to the fortune-demo/fortune-maven directory:
cd fortune-demo/fortune-maven
-
Create a native executable using the Maven plugin for Native Image:
mvn -Pnative package
The command compiles the project, creates a JAR file with all dependencies, and then generates a native executable,
fortune
, in the target/ directory, ready for use. -
Run the application:
./target/fortune
The application will return a random saying.
Requires GraalVM for JDK 21 for compatibility with Gradle. See Gradle Java Compatibility Matrix.
-
Change to the fortune-demo/fortune-gradle/ directory:
cd ../fortune-gradle
-
Create a native executable using the Gradle plugin for Native Image:
./gradlew nativeCompile
When the command completes, a native executable,
fortune
, is generated in the build/native/nativeCompile/ directory of the project and ready for use. -
Run the native executable:
./fortune/build/native/nativeCompile/fortune