Lightbend Activator

Akka Main in Java

Activator will be EOL-ed on May 24, 2017.

We’re making it easier and simpler for developers to get started with Lightbend technologies. This unfortunately means that future releases of Play, Akka and Scala will no longer include Activator support, and Lightbend’s Activator server will be decommissioned by the end of 2017. Instead of supporting Activator to create and set up development projects, we'll be supporting standard Giter8 templates for sbt users and Maven archetypes for Maven users. So going forward,

To create new Lightbend projects

Instead of using the Activator command, make sure you have sbt 0.13.13 (or higher), and use the “sbt new” command, providing the name of the template. For example, “$ sbt new akka/hello-akka.g8”. You can find a list of templates here.

Also, as a convenience, the Lightbend Project Starter allows you to quickly create a variety of example projects that you just unzip and run.

To create new templates

If you want to create new templates, you can now do that in Giter8.

To migrate templates from Activator to Giter8

If you created Activator templates in the past, please consider migrating them to Giter8 with this simple process.

Akka Main in Java

Akka Team
September 30, 2016
basics akka java starter

Actor based version of obligatory Hello World program using the generic launcher class akka.Main.

How to get "Akka Main in Java" on your computer

There are several ways to get this template.

Option 1: Choose akka-sample-main-java in the Lightbend Activator UI.

Already have Lightbend Activator (get it here)? Launch the UI then search for akka-sample-main-java in the list of templates.

Option 2: Download the akka-sample-main-java project as a zip archive

If you haven't installed Activator, you can get the code by downloading the template bundle for akka-sample-main-java.

  1. Download the Template Bundle for "Akka Main in Java"
  2. Extract the downloaded zip file to your system
  3. The bundle includes a small bootstrap script that can start Activator. To start Lightbend Activator's UI:

    In your File Explorer, navigate into the directory that the template was extracted to, right-click on the file named "activator.bat", then select "Open", and if prompted with a warning, click to continue:

    Or from a command line:

     C:\Users\typesafe\akka-sample-main-java> activator ui 
    This will start Lightbend Activator and open this template in your browser.

Option 3: Create a akka-sample-main-java project from the command line

If you have Lightbend Activator, use its command line mode to create a new project from this template. Type activator new PROJECTNAME akka-sample-main-java on the command line.

Option 4: View the template source

The creator of this template maintains it at

Option 5: Preview the tutorial below

We've included the text of this template's tutorial below, but it may work better if you view it inside Activator on your computer. Activator tutorials are often designed to be interactive.

Preview the tutorial

The Obligatory Hello World

Since every programming paradigm needs to solve the tough problem of printing a well-known greeting to the console we’ll introduce you to the actor-based version.


The HelloWorld actor is the application’s “main” class; when it terminates the application will shut down—more on that later. The main business logic happens in the preStart method, where a Greeter actor is created and instructed to issue that greeting we crave for. When the greeter is done it will tell us so by sending back a message, and when that message has been received it will be passed into the behavior described by the onReceive method where we can conclude the demonstration by stopping the HelloWorld actor.

The Greeter

You will be very curious to see how the Greeter actor performs the actual task. Open

This is extremely simple now: after its creation this actor will not do anything until someone sends it a message, and if that happens to be an invitation to greet the world then the Greeter complies and informs the requester that the deed has been done.

Main class

Go to the Run tab, and start the application main class sample.hello.Main. In the log output you can see the "Hello World!" greeting. is actually just a small wrapper around the generic launcher class akka.Main, which expects only one argument: the class name of the application’s main actor. This main method will then create the infrastructure needed for running the actors, start the given main actor and arrange for the whole application to shut down once the main actor terminates. Thus you will be able to run the application with a command similar to the following:

java -classpath  akka.Main sample.hello.HelloWorld

This conveniently assumes placement of the above class definitions in package sample.hello and it further assumes that you have the required JAR files for scala-library, typesafe-config and akka-actor available. The easiest would be to manage these dependencies with a build tool.

If you need more control of the startup code than what is provided by akka.Main you can easily write your own main class such as

Try to run the sample.hello.Main2 class by selecting it in the 'Main class' menu in the Run tab.

Run with Maven

This sample also includes a Maven pom.xml.

You can run the main classes with mvn from a terminal window using the Exec Maven Plugin.

mvn compile exec:java -Dexec.mainClass="akka.Main" -Dexec.args="sample.hello.HelloWorld"

mvn compile exec:java -Dexec.mainClass="sample.hello.Main2"