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.

Maven
<project>
    <modelVersion>4.0.0</modelVersion>

    <groupId>hello-akka-java</groupId>
    <artifactId>app</artifactId>
    <version>1.0</version>

    <properties>
      <akka.version>$akka_version$</akka.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-actor-typed_2.13</artifactId>
            <version>\${akka.version}</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-actor-testkit-typed_2.13</artifactId>
            <version>\${akka.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <configuration>
                    <executable>java</executable>
                    <arguments>
                        <argument>-classpath</argument>
                        <classpath />
                        <argument>com.lightbend.akka.sample.AkkaQuickstart</argument>
                    </arguments>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Gradle
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'


repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
  compile 'com.typesafe.akka:akka-actor-typed_2.13:$akka_version$'
  compile 'ch.qos.logback:logback-classic:1.2.3'
  testCompile 'com.typesafe.akka:akka-actor-testkit-typed_2.13:$akka_version$'
  testCompile 'junit:junit:4.12'
}

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

run {
  standardInput = System.in
}

Running the project

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

Maven
$ mvn compile exec:exec
Gradle
$ gradle run

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

Maven

``` canning for projects… [INFO] [INFO] ————————< hello-akka-java:app >————————- [INFO] Building app 1.0 [INFO] ——————————–[ jar ]——————————— [INFO] [INFO] — maven-resources-plugin:2.6:resources (default-resources) @ app — [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] [INFO] — exec-maven-plugin:1.6.0:exec (default-cli) @ app — [2019-10-12 09:20:30,248] [INFO] [akka.event.slf4j.Slf4jLogger] [helloakka-akka.actor.default-dispatcher-3] [] - Slf4jLogger started SLF4J: A number (1) of logging calls during the initialization phase have been intercepted and are SLF4J: now being replayed. These are subject to the filtering rules of the underlying logging system. SLF4J: See also http://www.slf4j.org/codes.html#replay

Press ENTER to exit <<< [2019-10-12 09:20:30,288] [INFO] [com.lightbend.akka.sample.Greeter] [helloakka-akka.actor.default-dispatcher-6] [akka://helloakka/user/greeter] - Hello Charles! [2019-10-12 09:20:30,290] [INFO] [com.lightbend.akka.sample.HelloWorldBot] [helloakka-akka.actor.default-dispatcher-3] [akka://helloakka/user/Charles] - Greeting 1 for Charles [2019-10-12 09:20:30,291] [INFO] [com.lightbend.akka.sample.Greeter] [helloakka-akka.actor.default-dispatcher-6] [akka://helloakka/user/greeter] - Hello Charles! [2019-10-12 09:20:30,291] [INFO] [com.lightbend.akka.sample.HelloWorldBot] [helloakka-akka.actor.default-dispatcher-3] [akka://helloakka/user/Charles] - Greeting 2 for Charles [2019-10-12 09:20:30,291] [INFO] [com.lightbend.akka.sample.Greeter] [helloakka-akka.actor.default-dispatcher-6] [akka://helloakka/user/greeter] - Hello Charles! [2019-10-12 09:20:30,291] [INFO] [com.lightbend.akka.sample.HelloWorldBot] [helloakka-akka.actor.default-dispatcher-3] [akka://helloakka/user/Charles] - Greeting 3 for Charles


Gradle : ``` :run [2019-10-12 09:47:16,399] [INFO] [akka.event.slf4j.Slf4jLogger] [helloakka-akka.actor.default-dispatcher-3] [] - Slf4jLogger started SLF4J: A number (1) of logging calls during the initialization phase have been intercepted and are SLF4J: now being replayed. These are subject to the filtering rules of the underlying logging system. SLF4J: See also http://www.slf4j.org/codes.html#replay >>> Press ENTER to exit <<< [2019-10-12 09:47:16,437] [INFO] [com.lightbend.akka.sample.Greeter] [helloakka-akka.actor.default-dispatcher-6] [akka://helloakka/user/greeter] - Hello Charles! [2019-10-12 09:47:16,439] [INFO] [com.lightbend.akka.sample.HelloWorldBot] [helloakka-akka.actor.default-dispatcher-3] [akka://helloakka/user/Charles] - Greeting 1 for Charles [2019-10-12 09:47:16,440] [INFO] [com.lightbend.akka.sample.Greeter] [helloakka-akka.actor.default-dispatcher-6] [akka://helloakka/user/greeter] - Hello Charles! [2019-10-12 09:47:16,440] [INFO] [com.lightbend.akka.sample.HelloWorldBot] [helloakka-akka.actor.default-dispatcher-3] [akka://helloakka/user/Charles] - Greeting 2 for Charles [2019-10-12 09:47:16,440] [INFO] [com.lightbend.akka.sample.Greeter] [helloakka-akka.actor.default-dispatcher-6] [akka://helloakka/user/greeter] - Hello Charles! [2019-10-12 09:47:16,440] [INFO] [com.lightbend.akka.sample.HelloWorldBot] [helloakka-akka.actor.default-dispatcher-3] [akka://helloakka/user/Charles] - Greeting 3 for Charles <=========----> 75% EXECUTING [27s] > :run

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 contains includes the time and name of the object the behavior was defined.

To run the tests, enter the test task instead:

Maven
$ mvn test
Gradle
$ gradle test

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!