From Akka' site docs:
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 above code with a command similar to the following:
java -classpath akka.Main example.two.HelloWorld
So, how can I launch it from IntelliJ IDEA? I have not found good/proper Window for that.
Dependecy to AKKA is already in the project:
<dependencies>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.10</artifactId>
<version>2.2-M3</version>
</dependency>
</dependencies>
The code itself (as you can see there is no main(...)
) :
public class HelloWorld extends UntypedActor {
@Override
public void preStart() {
// create the greeter actor
final ActorRef greeter =
getContext().actorOf(Props.create(Greeter.class), "greeter");
// tell it to perform the greeting
greeter.tell(Greeter.Msg.GREET, getSelf());
}
@Override
public void onReceive(Object msg) {
if (msg == Greeter.Msg.DONE) {
// when the greeter is done, stop this actor and with it the application
getContext().stop(getSelf());
} else unhandled(msg);
}
}
It seems like the documentation and the binary distributions are not in sync.
As you can see here on Github the
Main.scala
was added just 16 days ago.To fix this you can change the dependency version to the
SNAPSHOT
instead. Add the snapshot repository to the pom and change version to2.2-SNAPSHOT
:Now the
akka.Main
will be available. In order to start the application you will have to point to the correct main class and add your own actor class as an argument.First chose to create a new run configuration:
Then add a new application:
Give the application a name (Actor or something) and fill in the main class to be
akka.Main
and add yourHelloWorld
class asProgram Arguments
(remember to include the full package):And now you are ready to run the program, just press the play button in the tool bar:
Voila!