Fleet 1.0 Help

Getting started with Java

This tutorial gets you up to speed with Java development in Fleet. It covers the installation, project setup and working with code. In order to complete it, you need JetBrains Toolbox 1.22.10970 or later: the Download page.

Download and install Fleet

  1. Make sure you are logged in JetBrains Toolbox under your JetBrains Account.

  2. In JetBrains Toolbox, click Install near the Fleet icon.

    Download and install Fleet

Set up a workspace

Workspace is the directory where your project resides. It contains the project files and settings. You can open an existing project or start a new project by opening an empty directory.

In this tutorial, we will start a new project and have it initialized by a build tool (Maven or Gradle).

Open a workspace

  1. From the File menu, select Open ⌘O.

  2. In the file browser, navigate to an empty folder where you want to store your code and click Open.

When you open a directory, it becomes the root of a workspace. You can view its contents in the Files view.

Files tree

Now let's initialize the project. This will generate the boilerplate and some example code that we can use to try out Fleet in action. The steps differ depending on the build system. Use the tabs below to see the steps for a particular build system.

Initialize the project

  1. Make sure Gradle is installed on your computer.

  2. Press ⌘⌥T to open a terminal and execute the gradle init command.

  3. When prompted, answer:

    • Project type – 2 (application)

    • Implementation language – 3 (Java)

    • Split functionality across subprojects – 1 (no)

    • Build script DSL – 2 (Kotlin)

    • Generate build using new APIs and behavior – no

    • Test framework – 1 (JUnit 4)

    • Project name – skip

    • Source package – skip

Initialize the project

  1. Make sure Maven is installed on your computer.

  2. Press ⌘⌥T to open a terminal and execute the following command:

    mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false

By default, Fleet uses the JDK from your JAVA_HOME environment variable. Before proceeding, make sure it is configured in your environment. Otherwise, you can configure a custom JDK for your project.

Configure project JDK

  1. In the Files view, right-click the root folder, then select New Folder. Name it .fleet.

  2. Right-click the .fleet directory, then select New File ⌘N. Name the file settings.json.

  3. In settings.json, specify the path to your JDK in the following format:

    { "java.home": "/path/to/jdk/" }

Smart mode

You can use Fleet as a text editor, rather than a full-fledged IDE. However, if you need code intelligence features, you can enable them by turning the Smart Mode on.

Enable smart mode

  • In the top-right corner of the window, click Smart Mode Status, then Enable.

    Enable smart mode

After you click the Enable button, you may have to wait for some time, while the backend is being prepared.

Here's what you can do in Smart Mode. The below is not an exhaustive list of Smart Mode features, rather a couple of examples that'll help you to get the feel of how it works in Fleet.

Use quick-fixes and intention actions

  • Press ⌥↵ to access actions that Fleet suggests in the current context.

    Intentions java

Refactor code

  • Place the caret at a literal or select an expression, then press ⌘⌥V.

    Extract variable java

    A variable is extracted from the selection.

Navigate the codebase

  • Navigate to the declaration of a symbol with ⌘B.

  • Use inlay hints navigate to usages and hierarchy members.

    Usages inlay java
  • Skim over the errors with ⌘E and ⌘⇧E

Use live templates

  • To generate a for loop, type fori and press . Press as you fill in the necessary variables.

    Template fori java

Run and Debug

With Smart Mode enabled, you can run your project. For that, you can use a gutter icon in the editor, or you can create a run configuration that will allow you to fine-tune the way your application should be run.

Run from the editor

  • Navigate to the entry point of your application and click the run icon in the gutter. Select Run.

    Java fleet run from gutter

As mentioned before, another way to run a program is to use a run configuration. It allows you to customize the startup: add arguments, use custom commands, environment variables and so on.

Create a run configuration

  1. Press ⌘R. Run & Debug dialog opens.

    Create run json 0

    Click Create Run Configurations.

  2. In run.json, append a gradle run configuration to the array, so that the resulting JSON looks like the following:

    { "configurations": [ { "name": "run sh", "type": "command", "program": "/bin/sh" }, { "name": "gradle run", "type": "gradle", "tasks": [ "run" ] } ] }

Launch a run configuration

  • Press ⌘R. The Run dialog opens. Select the newly created gradle run configuration.

    The application runs, and you can review its output in the console that opens.

    Console 0

Debug the application

  1. If you are going to launch the debug session using a run configuration, add "debugJvm": "true", to the run configuration you are using, so that it looks like the following:

    { "name": "gradle run", "debugJvm": "true", "type": "gradle", "tasks": [ "run" ] }
  2. Set a breakpoint by clicking at an executable line in the gutter. This will suspend the application just when this line is about to execute.

    Breakpoint
  3. Run the application by selecting Debug from the gutter menu or launching a previously saved run configuration.

    All application threads get suspended when any of them reaches the line with the breakpoint.

    Breakpoint suspend
  4. Inspect the program state in the Run and debug panel. As we are using a hello-world type of app here, we don't have a lot of state to inspect.

    The buttons above the threads list let you control the program execution. You can advance it line-by-line, step in and out of methods, resume and stop the program.

    Threads
Last modified: 07 June 2022