2.2. Manual Project Setup

Note: This page is written specifically for Linux users. The commands may need to be tweaked for Windows users but the general steps should be the same.

To initiate the setup of a SwimOS project, start by creating and navigating to the directory where it will be located. We will be using the tutorial directory with the same project name.

Following this, we’ll configure our build tool to streamline dependency management and facilitate seamless application execution. Typically, we opt for Gradle in our applications, and the basic setup will be covered in the upcoming section. If you prefer to use a different build tool, like Maven, feel free to do so, although the specifics are beyond the scope of this guide.

Gradle Setup

Gradle documentation and installation instructions can be found here.

From the blank project run the following command, feel free to tweak the configuration to suit you:

$ gradle init --type basic --dsl groovy

Once initialized, several Gradle specific configuration files will have been created, open the build.gradle file. This file is the build script that allows you to configure how the project is built and run, including dependencies for your Java project. Copy the following snippet into the script.

File: build.gradle

apply plugin: 'application'

version = '0.0.1'
mainClassName = 'tutorial.MainPlane'
ext.moduleName = 'tutorial'

repositories {
    mavenCentral()
}

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

The application plugin, combined with the mainClassName property, enables us to execute a designated Java class as our application using the run task. In the upcoming section, we’ll generate the MainPlane class, serving as the entry point for our code.

The repositories and dependencies sections in the file will enable us to incorporate SwimOS libraries into our application.

The src Directory

With the build tool configured, let’s proceed to establish the directory structure for the project source code. Create the necessary directories and construct the following tree within your project:

src
└── main
    ├── java
    │    └── tutorial
    └── resources

Finally, create two blank files:

On the upcoming page, we’ll delve into the details of these empty files. With this setup, our project is now ready for some code.