Skip to content

Latest commit

 

History

History

fortune-demo

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Native Image Fortune Demo

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:

Preparation

  1. 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.

  2. Download or clone the GraalVM demos repository:

    git clone https://github.com/graalvm/graalvm-demos

Fortune Maven Demo

  1. Change to the fortune-demo/fortune-maven directory:

    cd fortune-demo/fortune-maven
  2. 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.

  3. Run the application:

    ./target/fortune

    The application will return a random saying.

Fortune Gradle Demo

Requires GraalVM for JDK 21 for compatibility with Gradle. See Gradle Java Compatibility Matrix.

  1. Change to the fortune-demo/fortune-gradle/ directory:

    cd ../fortune-gradle
  2. 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.

  3. Run the native executable:

    ./fortune/build/native/nativeCompile/fortune

Learn More