Setup Java Project

Now that our development environment is setup, let’s create a new Gradle project so we can begin coding.

First, create a new directory called ‘lab2’ for our project and change into it.

mkdir lab2
cd lab2

Now initialize Gradle for our project.

gradle init --type java-application

When prompted, select Groovy for the build script DSL and JUnit 4 for the test framework. Press Enter to keep the default values for project name and package.

Initialize Gradle

In the left-hand navigation, click the arrow next to the ‘lab2’ folder to expand it. In this folder, you will see the build.gradle file. Open the build.gradle file in the IDE by double-clicking on it.

build.gradle build.gradle

Add the following lines to the dependencies section of the file to incorporate the third-party libraries we’ll need for the lab.

implementation ''
implementation ''
implementation 'com.amazonaws:aws-java-sdk-qldb:1.11.785'

The dependencies section of the file should now look like the following:

dependencies {
    // This dependency is used by the application.
    implementation ''

    // Use JUnit test framework
    testImplementation 'junit:junit:4.13'

    implementation ''
    implementation ''
    implementation 'com.amazonaws:aws-java-sdk-qldb:1.11.785'

Add the following line to the repositories section of the build.gradle file.


The repositories section of the file should now look like the following:

repositories {
    // Use jcenter for resolving dependencies.
    // You can declare any Maven/Ivy/file repository here.

Save the build.gradle file by clicking “File” on the menu bar and then clicking “Save”.

Open the file in the IDE by double-clicking on it in the left-hand navigation. The file is located in /qldb-lab2/lab2/app/src/main/java/lab2 in the project tree or /home/ec2-user/environment/lab2/app/src/main/java/lab2 on the filesystem.

Replace the contents of the file with the code below.

package lab2;

public class App {

    public static void main(String[] args) {
        System.out.println("Let's play with Ion!");

Save the file.

Gradle creates a unit test during initialization. We won’t be working with the unit test in this lab, so let’s remove it to keep it from failing during builds as we work with the file.

Find the /qldb-lab2/lab2/app/src/test/java/lab2/ file in the left-hand navigation in the IDE. Right-click the file and select ‘Delete’. Click ‘Yes’ to confirm deletion.

Make sure that your terminal session is in the same directory as the build.gradle file.


Make sure that all of your files have been saved before proceeding. Click “File” and “Save All”.


Test the program by running the command below in Cloud9’s terminal window.

gradle run

You should see the output depicted below. Test Output

Now that we know our environment is setup correctly and we can compile and execute Java programs, let’s begin using Amazon Ion.