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 files.

The build files

As you can see below the build files for Maven (pom.xml) and Gradle (build.gradle) used in this sample project are very simple. Please refer to the documentation of the build tool of your choice for more information.



                        <classpath />
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'

repositories {

dependencies {
  compile 'com.typesafe.akka:akka-actor_2.12:2.5.3'
  testCompile 'com.typesafe.akka:akka-testkit_2.12:2.5.3'
  testCompile 'junit:junit:4.12'

mainClassName = "com.lightbend.akka.sample.AkkaQuickstart"

run {
  standardInput =

Running the project

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

$ mvn compile exec:exec
$ gradle run

The output should look something like this (scroll all the way to the right to see the Actor output):

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building app 1.0
[INFO] ------------------------------------------------------------------------
[INFO] --- exec-maven-plugin:1.6.0:exec (default-cli) @ app ---
>>> Press ENTER to exit <<<
[INFO] [05/11/2017 14:07:20.790] [] [akka://helloakka/user/printerActor] Hello, Java
[INFO] [05/11/2017 14:07:20.791] [] [akka://helloakka/user/printerActor] Good day, Play
[INFO] [05/11/2017 14:07:20.791] [] [akka://helloakka/user/printerActor] Howdy, Akka
[INFO] [05/11/2017 14:07:20.791] [] [akka://helloakka/user/printerActor] Howdy, Lightbend
:compileJava UP-TO-DATE
:processResources NO-SOURCE
:classes UP-TO-DATE
>>> Press ENTER to exit <<<
[INFO] [05/11/2017 14:08:22.884] [] [akka://helloakka/user/printerActor] Howdy, Akka
[INFO] [05/11/2017 14:08:22.884] [] [akka://helloakka/user/printerActor] Good day, Play
[INFO] [05/11/2017 14:08:22.884] [] [akka://helloakka/user/printerActor] Hello, Java
[INFO] [05/11/2017 14:08:22.884] [] [akka://helloakka/user/printerActor] Howdy, Lightbend
<=========----> 75% EXECUTING
> :run

Remember that we set our Printer Actor to use the Logger from Akka? This is why there is a lot of extra information when we log things. The log output contains information like when and from what actor it was logged. Let’s focus on the output from the Printer Actor for a while:

... Howdy, Akka
... Hello, Java
... Good day, Play
... Howdy, Lightbend

This is the result of our code that sends messages to the Greeter Actor:

howdyGreeter.tell(new WhoToGreet("Akka"), ActorRef.noSender());
howdyGreeter.tell(new Greet(), ActorRef.noSender());

howdyGreeter.tell(new WhoToGreet("Lightbend"), ActorRef.noSender());
howdyGreeter.tell(new Greet(), ActorRef.noSender());

helloGreeter.tell(new WhoToGreet("Java"), ActorRef.noSender());
helloGreeter.tell(new Greet(), ActorRef.noSender());

goodDayGreeter.tell(new WhoToGreet("Play"), ActorRef.noSender());
goodDayGreeter.tell(new Greet(), ActorRef.noSender());

To run the tests, enter the test task instead:

$ mvn test
$ gradle test

Try running the code a couple of more times and make sure to notice the order of the logging. Did you notice that it can change from one run to another. What’s happening here? The asynchronous behavior becomes evident. This might be a new mental model for you. But, once you gain experience with it everything will become clear; just like for Neo in the Matrix.

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!