2.1. Project Setup with swim-create

To initiate the development of a SwimOS application, start by establishing the project in which your code will reside.

For Linux users, SwimOS offers a convenient command-line tool that swiftly initializes an empty SwimOS project. However, if you’re using Windows, proceed to the next page for manual instructions on setting up your project.

The swim-create Tool

To install the swim-create tool simply run the following command:

$ curl -L https://github.com/nstreamio/swim-create/releases/latest/download/swim-create-x86_64-unknown-linux-gnu.tar.gz | sudo tar -xz -C /usr/local/bin

With the swim-create command at your disposal, go to the directory where you intend to create your SwimOS project. Execute the swim-create command, specifying the desired name for your project/application. In this example, we’ve named it ‘tutorial’.

$ swim-create tutorial

An empty SwimOS project has now been created with the given name, navigate into it or open it in an IDE.

At SwimOS, we employ Gradle as our primary build tool, and you’ll find that the project comes pre-configured with Gradle settings. For those unfamiliar with Gradle as a build tool, feel free to read more here. The pivotal file introduced by Gradle in the project is the build.gradle script. Take note that this file includes the SwimOS dependency.

File: build.gradle

dependencies {
    implementation group: 'org.swimos', name: 'swim-server', version: '4.1.0.12'
}

Gradle also allows us to run some defined tasks using the gradlew wrapper script. Let’s test this by starting the blank SwimOS server using the run task:

$ ./gradlew run

You should see some log lines indicating that the server has started and is running. You can exit and stop the server at any time with Ctrl+C.

> Task :run
Starting server...
Running server...
<=========----> 75% EXECUTING [1s]
> :run

Alongside the Gradle configuration files, you’ll find a src directory within the project. This directory serves as the primary workspace, housing both the server configuration file (src/main/resources/server.recon) and the code that you’ll be writing. We will discuss these files more when we write our ‘Hello, world!’ application at the end of this chapter.