# How to install / recompile the example apps from the command line

These versions (or later) should be downloaded and installed:

- OpenJDK Java 12: OpenJDK Java Development Kit 12.0.2
- Maven 3.6.2 Maven
- Swirlds SDK: Swirlds SDK

The above link is to OpenJDK 12, which is free. Oracle JDK 11+ requires a paid license.

If the Swirlds browser freezes when it is first launched, it is possible that the operating system needs a utility installed to collect entropy, such as the utilities for Debian or Raspbian.

These examples will uses slashes in paths, but on Windows they will be backslashes.

Download and unzip the SDK. This gives a directory with a number of files and subdirectories, including these:

        sdk/data/apps/
        sdk/swirlds.jar
        sdk/config.txt

The last one, config.txt, is used to make the Swirlds browser automatically run a particular app. It can even make multiple instances of it run and communicate with each other, as if they were on multiple machines. The comments in the file explain how to change it.

The demo apps are now ready to run.

The apps come with source code, and can be recompiled from the command line, by executing mvn install in the directory of a demo, then running swirlds.jar. The following walks through an example of doing this.

- From the command line, change directory into sdk
- Run the hashgraph demo by typing:

        java -jar swirlds.jar

- Edit the config.txt file with any text editor, such as by typing:

        nano config.txt

- The file has a line near the top starting with StatsDemo, and another line near it starting with # HelloSwirldDemo. Add a # character at the start of the StatsDemo line to comment it out, and delete the # from the start of the HelloSwirldDemo line to uncomment it.
- Run the Hello Swirld demo by typing:

        java -jar swirlds.jar

- Now edit the source file of the demo, to change what it does (instead of nano, this can be done with emacs or vi or any other text editor):

        cd source/HelloSwirldDemo
        nano HelloSwirldDemoMain.java

- Make a change to the string in this line, which is near the top of the run() method:

        console.out.println("Hello Swirld from " + myName);

- Recompile and run it, to see the new effect of the change:

        mvn install
        cd ../..
        java -jar swirlds.jar

- That should now reflect the change that was made. After the line that was changed, insert this new line:

        System.out.println("printing to the command line console");

- Recompile and run as above, and the string should print to the command line console where it was run. So to see that output, it needs to be run from a console rather than by double clicking on the swirlds.jar file icon.
- The above steps can be repeated to develop a new app, entirely from the command line. Though it may be easier to use an Integrated Development Environment (IDE).

Back