Running the application

You can run the Hello World application from the command line or an IDE. The final topic in this guide describes how to run it from IntelliJ IDEA. But, before we run the application again, let’s take a quick look at the build tool: sbt.

The build files

sbt uses a build.sbt file to handle the project. This project’s build.sbt file looks like this:

name := "$name$"

version := "1.0"

scalaVersion := s"$scala_version$"

resolvers += "Akka library repository".at("https://repo.akka.io/maven")

lazy val akkaVersion = "$akka_version$"

// Run in a separate JVM, to make sure sbt waits until all threads have
// finished before returning.
// If you want to keep the application running while executing other
// sbt tasks, consider https://github.com/spray/sbt-revolver/
fork := true

libraryDependencies ++= Seq(
  "com.typesafe.akka" %% "akka-actor-typed" % akkaVersion,
  "ch.qos.logback" % "logback-classic" % "1.2.13",
  "com.typesafe.akka" %% "akka-actor-testkit-typed" % akkaVersion % Test,
  "org.scalatest" %% "scalatest" % "3.2.15" % Test
)

This build file is very simple. In essence, it creates one project hello-akka-scala and declares project dependencies. We must also declare what version of sbt to use and this is done in the file project/build.properties:

sbt.version=$sbt_version$

Running the project

Just as you did earlier, run the application from a console:

  1. Enter ./sbt on OSX/Linux or sbt.bat on Windows
    sbt downloads project dependencies. The > prompt indicates sbt has started in interactive mode.

  2. At the sbt prompt, enter reStart.
    The output should look something like this (scroll all the way to the right to see the Actor output):

[2019-10-09 09:55:23,390] [INFO] [com.example.Greeter$] [AkkaQuickStart-akka.actor.default-dispatcher-5]
[akka://AkkaQuickStart/user/greeter] - Hello Charles!
[2019-10-09 09:55:23,392] [INFO] [com.example.GreeterBot$] [AkkaQuickStart-akka.actor.default-dispatcher-3]
[akka://AkkaQuickStart/user/Charles] - Greeting 1 for Charles
[2019-10-09 09:55:23,392] [INFO] [com.example.Greeter$] [AkkaQuickStart-akka.actor.default-dispatcher-5]
[akka://AkkaQuickStart/user/greeter] - Hello Charles!
[2019-10-09 09:55:23,392] [INFO] [com.example.GreeterBot$] [AkkaQuickStart-akka.actor.default-dispatcher-3]
[akka://AkkaQuickStart/user/Charles] - Greeting 2 for Charles
[2019-10-09 09:55:23,392] [INFO] [com.example.Greeter$] [AkkaQuickStart-akka.actor.default-dispatcher-5]
[akka://AkkaQuickStart/user/greeter] - Hello Charles!
[2019-10-09 09:55:23,392] [INFO] [com.example.GreeterBot$] [AkkaQuickStart-akka.actor.default-dispatcher-3]
[akka://AkkaQuickStart/user/Charles] - Greeting 3 for Charles

Remember that the implementation of the Greeter Actor used the logger from the ActorContext? This provides a lot of extra information. For example, the log output includes the time and name of the object for which the behavior was defined.

To run the tests, enter test at the sbt prompt.

Next steps

If you use IntelliJ, try integrating the sample project with IntelliJ IDEA.

To continue learning more about Akka and Actor Systems, look at the Getting Started Guide next. Happy hakking!