diff --git a/.gitignore b/.gitignore index 0863ff8a05..b92e37e421 100755 --- a/.gitignore +++ b/.gitignore @@ -71,3 +71,5 @@ tm*.lck tm*.log tm.out worker*.log +*-shim.sbt + diff --git a/akka-docs/rst/java/hello-world.rst b/akka-docs/rst/java/hello-world.rst index 5ba984e1a2..faa9e36aa9 100644 --- a/akka-docs/rst/java/hello-world.rst +++ b/akka-docs/rst/java/hello-world.rst @@ -2,42 +2,17 @@ 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 actor based version of the tough problem of printing a +well-known greeting to the console is introduced in a `Typesafe Activator `_ +tutorial named `Akka Main in Java `_. -.. includecode:: ../java/code/docs/actor/japi/HelloWorld.java#hello-world - -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 :meth:`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 :meth:`onReceive` method where we can -conclude the demonstration by stopping the ``HelloWorld`` actor. You will be -very curious to see how the ``Greeter`` actor performs the actual task: - -.. includecode:: ../java/code/docs/actor/japi/Greeter.java#greeter - -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. - -As a Java developer you will probably want to tell us that there is no -``static public void main(...)`` anywhere in these classes, so how do we run -this program? The answer is that the appropriate :meth:`main` method is -implemented in the generic launcher class :class:`akka.Main` which expects only +The tutorial illustrates the generic launcher class :class:`akka.Main` which expects only one command line 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 above code -with a command similar to the following:: +once the main actor terminates. - java -classpath akka.Main com.example.HelloWorld - -This conveniently assumes placement of the above class definitions in package -``com.example`` and it further assumes that you have the required JAR files for -``scala-library`` and ``akka-actor`` available. The easiest would be to manage -these dependencies with a build tool, see :ref:`build-tool`. +There is also another `Typesafe Activator `_ +tutorial in the same problem domain that is named `Hello Akka! `_. +It describes the basics of Akka in more depth. diff --git a/akka-docs/rst/scala/code/docs/actor/IntroDocSpec.scala b/akka-docs/rst/scala/code/docs/actor/IntroDocSpec.scala deleted file mode 100644 index 42ca19e51d..0000000000 --- a/akka-docs/rst/scala/code/docs/actor/IntroDocSpec.scala +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright (C) 2009-2013 Typesafe Inc. - */ - -package docs.actor - -import akka.testkit.AkkaSpec - -//#hello-world -import akka.actor.Actor -import akka.actor.Props - -class HelloWorld extends Actor { - - override def preStart(): Unit = { - // create the greeter actor - val greeter = context.actorOf(Props[Greeter], "greeter") - // tell it to perform the greeting - greeter ! Greeter.Greet - } - - def receive = { - // when the greeter is done, stop this actor and with it the application - case Greeter.Done ⇒ context.stop(self) - } -} -//#hello-world - -//#greeter -object Greeter { - case object Greet - case object Done -} - -class Greeter extends Actor { - def receive = { - case Greeter.Greet ⇒ - println("Hello World!") - sender ! Greeter.Done - } -} -//#greeter - -class IntroDocSpec extends AkkaSpec { - - "demonstrate HelloWorld" in { - expectTerminated(watch(system.actorOf(Props[HelloWorld]))) - } - -} \ No newline at end of file diff --git a/akka-docs/rst/scala/hello-world.rst b/akka-docs/rst/scala/hello-world.rst index ad79cbe505..1691482d8e 100644 --- a/akka-docs/rst/scala/hello-world.rst +++ b/akka-docs/rst/scala/hello-world.rst @@ -2,43 +2,17 @@ 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 actor based version of the tough problem of printing a +well-known greeting to the console is introduced in a `Typesafe Activator `_ +tutorial named `Akka Main in Scala `_. -.. includecode:: ../scala/code/docs/actor/IntroDocSpec.scala#hello-world +The tutorial illustrates the generic launcher class :class:`akka.Main` which expects only +one command line 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. -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 :meth:`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 :meth:`receive` -method where we can conclude the demonstration by stopping the ``HelloWorld`` -actor. You will be very curious to see how the ``Greeter`` actor performs the -actual task: - -.. includecode:: ../scala/code/docs/actor/IntroDocSpec.scala#greeter - -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. - -As a Scala developer you will probably want to tell us that there is no -``main(Array[String])`` method anywhere in these classes, so how do we run this -program? The answer is that the appropriate :meth:`main` method is implemented -in the generic launcher class :class:`akka.Main` which expects only one command -line 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 above code with a -command similar to the following:: - - java -classpath akka.Main com.example.HelloWorld - -This conveniently assumes placement of the above class definitions in package -``com.example`` and it further assumes that you have the required JAR files for -``scala-library`` and ``akka-actor`` available. The easiest would be to manage -these dependencies with a build tool, see :ref:`build-tool`. +There is also another `Typesafe Activator `_ +tutorial in the same problem domain that is named `Hello Akka! `_. +It describes the basics of Akka in more depth. diff --git a/akka-samples/akka-sample-hello/README.md b/akka-samples/akka-sample-hello/README.md deleted file mode 100644 index ebce03e807..0000000000 --- a/akka-samples/akka-sample-hello/README.md +++ /dev/null @@ -1,13 +0,0 @@ -HELLO -===== - -This sample is meant to be used by studying the code; it does not perform any -astounding functions when running it. If you want to run it, check out the akka -sources on your local hard drive, follow the [instructions for setting up Akka -with SBT](http://doc.akka.io/docs/akka/current/intro/getting-started.html). -When you start SBT within the checked-out akka source directory, you can run -this sample by typing - - akka-sample-hello/run - -You can read more in the [Akka docs](http://akka.io/docs). diff --git a/akka-samples/akka-sample-hello/src/main/scala/sample/hello/Main.scala b/akka-samples/akka-sample-hello/src/main/scala/sample/hello/Main.scala deleted file mode 100644 index 3767bfb890..0000000000 --- a/akka-samples/akka-sample-hello/src/main/scala/sample/hello/Main.scala +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright (C) 2009-2013 Typesafe Inc. - */ -package sample.hello - -import akka.actor.{ ActorSystem, Actor, Props } - -case object Start - -object Main { - def main(args: Array[String]): Unit = { - val system = ActorSystem() - system.actorOf(Props[HelloActor]) ! Start - } -} - -class HelloActor extends Actor { - val worldActor = context.actorOf(Props[WorldActor]) - def receive = { - case Start ⇒ worldActor ! "Hello" - case s: String ⇒ - println("Received message: %s".format(s)) - context.system.shutdown() - } -} - -class WorldActor extends Actor { - def receive = { - case s: String ⇒ sender ! s.toUpperCase + " world!" - } -} - diff --git a/akka-samples/akka-sample-main-java/LICENSE b/akka-samples/akka-sample-main-java/LICENSE new file mode 100644 index 0000000000..a02154466b --- /dev/null +++ b/akka-samples/akka-sample-main-java/LICENSE @@ -0,0 +1,13 @@ +Copyright 2013 Typesafe, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/akka-samples/akka-sample-main-java/activator.properties b/akka-samples/akka-sample-main-java/activator.properties new file mode 100644 index 0000000000..26d450b5b1 --- /dev/null +++ b/akka-samples/akka-sample-main-java/activator.properties @@ -0,0 +1,4 @@ +name=akka-sample-main-java +title=Akka Main in Java +description=Actor based version of obligatory Hello World program using the generic launcher class akka.Main. +tags=Basics,akka,java,java,starter diff --git a/akka-samples/akka-sample-main-java/build.sbt b/akka-samples/akka-sample-main-java/build.sbt new file mode 100644 index 0000000000..4d6728a29c --- /dev/null +++ b/akka-samples/akka-sample-main-java/build.sbt @@ -0,0 +1,10 @@ +name := "akka-sample-main-java" + +version := "1.0" + +scalaVersion := "2.10.3" + +libraryDependencies ++= Seq( + "com.typesafe.akka" %% "akka-actor" % "2.3-SNAPSHOT" +) + diff --git a/akka-samples/akka-sample-main-java/project/build.properties b/akka-samples/akka-sample-main-java/project/build.properties new file mode 100644 index 0000000000..0974fce44d --- /dev/null +++ b/akka-samples/akka-sample-main-java/project/build.properties @@ -0,0 +1 @@ +sbt.version=0.13.0 diff --git a/akka-docs/rst/java/code/docs/actor/japi/Greeter.java b/akka-samples/akka-sample-main-java/src/main/java/sample/hello/Greeter.java similarity index 76% rename from akka-docs/rst/java/code/docs/actor/japi/Greeter.java rename to akka-samples/akka-sample-main-java/src/main/java/sample/hello/Greeter.java index 239b615a05..2669d619e8 100644 --- a/akka-docs/rst/java/code/docs/actor/japi/Greeter.java +++ b/akka-samples/akka-sample-main-java/src/main/java/sample/hello/Greeter.java @@ -1,26 +1,23 @@ /** * Copyright (C) 2009-2013 Typesafe Inc. */ - -package docs.actor.japi; +package sample.hello; import akka.actor.UntypedActor; -import java.io.Serializable; -//#greeter public class Greeter extends UntypedActor { - + public static enum Msg { GREET, DONE; } - + @Override public void onReceive(Object msg) { if (msg == Msg.GREET) { System.out.println("Hello World!"); getSender().tell(Msg.DONE, getSelf()); - } else unhandled(msg); + } else + unhandled(msg); } - + } -//#greeter diff --git a/akka-docs/rst/java/code/docs/actor/japi/HelloWorld.java b/akka-samples/akka-sample-main-java/src/main/java/sample/hello/HelloWorld.java similarity index 76% rename from akka-docs/rst/java/code/docs/actor/japi/HelloWorld.java rename to akka-samples/akka-sample-main-java/src/main/java/sample/hello/HelloWorld.java index 396b1881b3..7005a20387 100644 --- a/akka-docs/rst/java/code/docs/actor/japi/HelloWorld.java +++ b/akka-samples/akka-sample-main-java/src/main/java/sample/hello/HelloWorld.java @@ -2,9 +2,8 @@ * Copyright (C) 2009-2013 Typesafe Inc. */ -package docs.actor.japi; +package sample.hello; -//#hello-world import akka.actor.Props; import akka.actor.UntypedActor; import akka.actor.ActorRef; @@ -14,8 +13,7 @@ public class HelloWorld extends UntypedActor { @Override public void preStart() { // create the greeter actor - final ActorRef greeter = - getContext().actorOf(Props.create(Greeter.class), "greeter"); + final ActorRef greeter = getContext().actorOf(Props.create(Greeter.class), "greeter"); // tell it to perform the greeting greeter.tell(Greeter.Msg.GREET, getSelf()); } @@ -25,7 +23,7 @@ public class HelloWorld extends UntypedActor { if (msg == Greeter.Msg.DONE) { // when the greeter is done, stop this actor and with it the application getContext().stop(getSelf()); - } else unhandled(msg); + } else + unhandled(msg); } } -//#hello-world \ No newline at end of file diff --git a/akka-samples/akka-sample-main-java/src/main/java/sample/hello/Main.java b/akka-samples/akka-sample-main-java/src/main/java/sample/hello/Main.java new file mode 100644 index 0000000000..c5a88313e6 --- /dev/null +++ b/akka-samples/akka-sample-main-java/src/main/java/sample/hello/Main.java @@ -0,0 +1,11 @@ +/** + * Copyright (C) 2009-2013 Typesafe Inc. + */ +package sample.hello; + +public class Main { + + public static void main(String[] args) { + akka.Main.main(new String[] { HelloWorld.class.getName() }); + } +} diff --git a/akka-samples/akka-sample-main-java/src/main/java/sample/hello/Main2.java b/akka-samples/akka-sample-main-java/src/main/java/sample/hello/Main2.java new file mode 100644 index 0000000000..42db74b69f --- /dev/null +++ b/akka-samples/akka-sample-main-java/src/main/java/sample/hello/Main2.java @@ -0,0 +1,43 @@ +/** + * Copyright (C) 2009-2013 Typesafe Inc. + */ +package sample.hello; + +import akka.actor.ActorRef; +import akka.actor.ActorSystem; +import akka.actor.Props; +import akka.actor.Terminated; +import akka.actor.UntypedActor; +import akka.event.Logging; +import akka.event.LoggingAdapter; + +public class Main2 { + + public static void main(String[] args) { + ActorSystem system = ActorSystem.create("Hello"); + ActorRef a = system.actorOf(Props.create(HelloWorld.class), "helloWorld"); + system.actorOf(Props.create(Terminator.class, a), "terminator"); + } + + public static class Terminator extends UntypedActor { + + private final LoggingAdapter log = Logging.getLogger(getContext().system(), this); + private final ActorRef ref; + + public Terminator(ActorRef ref) { + this.ref = ref; + getContext().watch(ref); + } + + @Override + public void onReceive(Object msg) { + if (msg instanceof Terminated) { + log.info("{} has terminated, shutting down system", ref.path()); + getContext().system().shutdown(); + } else { + unhandled(msg); + } + } + + } +} diff --git a/akka-samples/akka-sample-main-java/tutorial/index.html b/akka-samples/akka-sample-main-java/tutorial/index.html new file mode 100644 index 0000000000..bcd533053e --- /dev/null +++ b/akka-samples/akka-sample-main-java/tutorial/index.html @@ -0,0 +1,96 @@ + + + The Obligatory Hello World + + + + +
+

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

+ +

+Open HelloWorld.java +

+ +

+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 receive +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 Greeter.java. +

+ +

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

+ +

+Main.java +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 +Main2.java +

+ +

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

+ +
+ + + diff --git a/akka-samples/akka-sample-main-scala/LICENSE b/akka-samples/akka-sample-main-scala/LICENSE new file mode 100644 index 0000000000..a02154466b --- /dev/null +++ b/akka-samples/akka-sample-main-scala/LICENSE @@ -0,0 +1,13 @@ +Copyright 2013 Typesafe, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/akka-samples/akka-sample-main-scala/activator.properties b/akka-samples/akka-sample-main-scala/activator.properties new file mode 100644 index 0000000000..e15e7c3dc9 --- /dev/null +++ b/akka-samples/akka-sample-main-scala/activator.properties @@ -0,0 +1,4 @@ +name=akka-sample-main-scala +title=Akka Main in Scala +description=Actor based version of obligatory Hello World program using the generic launcher class akka.Main. +tags=Basics,akka,java,scala,starter diff --git a/akka-samples/akka-sample-main-scala/build.sbt b/akka-samples/akka-sample-main-scala/build.sbt new file mode 100644 index 0000000000..410850f86b --- /dev/null +++ b/akka-samples/akka-sample-main-scala/build.sbt @@ -0,0 +1,10 @@ +name := "akka-sample-main-scala" + +version := "1.0" + +scalaVersion := "2.10.3" + +libraryDependencies ++= Seq( + "com.typesafe.akka" %% "akka-actor" % "2.3-SNAPSHOT" +) + diff --git a/akka-samples/akka-sample-main-scala/project/build.properties b/akka-samples/akka-sample-main-scala/project/build.properties new file mode 100644 index 0000000000..0974fce44d --- /dev/null +++ b/akka-samples/akka-sample-main-scala/project/build.properties @@ -0,0 +1 @@ +sbt.version=0.13.0 diff --git a/akka-samples/akka-sample-main-scala/src/main/scala/sample/hello/Greeter.scala b/akka-samples/akka-sample-main-scala/src/main/scala/sample/hello/Greeter.scala new file mode 100644 index 0000000000..799d978b6e --- /dev/null +++ b/akka-samples/akka-sample-main-scala/src/main/scala/sample/hello/Greeter.scala @@ -0,0 +1,19 @@ +/** + * Copyright (C) 2009-2013 Typesafe Inc. + */ +package sample.hello + +import akka.actor.Actor + +object Greeter { + case object Greet + case object Done +} + +class Greeter extends Actor { + def receive = { + case Greeter.Greet ⇒ + println("Hello World!") + sender ! Greeter.Done + } +} \ No newline at end of file diff --git a/akka-samples/akka-sample-main-scala/src/main/scala/sample/hello/HelloWorld.scala b/akka-samples/akka-sample-main-scala/src/main/scala/sample/hello/HelloWorld.scala new file mode 100644 index 0000000000..cec140b89c --- /dev/null +++ b/akka-samples/akka-sample-main-scala/src/main/scala/sample/hello/HelloWorld.scala @@ -0,0 +1,23 @@ +/** + * Copyright (C) 2009-2013 Typesafe Inc. + */ +package sample.hello + +import akka.actor.Actor +import akka.actor.Props + +class HelloWorld extends Actor { + + override def preStart(): Unit = { + // create the greeter actor + val greeter = context.actorOf(Props[Greeter], "greeter") + // tell it to perform the greeting + greeter ! Greeter.Greet + } + + def receive = { + // when the greeter is done, stop this actor and with it the application + case Greeter.Done ⇒ context.stop(self) + } +} + diff --git a/akka-samples/akka-sample-main-scala/src/main/scala/sample/hello/Main.scala b/akka-samples/akka-sample-main-scala/src/main/scala/sample/hello/Main.scala new file mode 100644 index 0000000000..0b2c907a94 --- /dev/null +++ b/akka-samples/akka-sample-main-scala/src/main/scala/sample/hello/Main.scala @@ -0,0 +1,12 @@ +/** + * Copyright (C) 2009-2013 Typesafe Inc. + */ +package sample.hello + +object Main { + + def main(args: Array[String]): Unit = { + akka.Main.main(Array(classOf[HelloWorld].getName)) + } + +} \ No newline at end of file diff --git a/akka-samples/akka-sample-main-scala/src/main/scala/sample/hello/Main2.scala b/akka-samples/akka-sample-main-scala/src/main/scala/sample/hello/Main2.scala new file mode 100644 index 0000000000..51e267c2e9 --- /dev/null +++ b/akka-samples/akka-sample-main-scala/src/main/scala/sample/hello/Main2.scala @@ -0,0 +1,30 @@ +/** + * Copyright (C) 2009-2013 Typesafe Inc. + */ +package sample.hello + +import akka.actor.ActorSystem +import akka.actor.Props +import akka.actor.ActorRef +import akka.actor.Actor +import akka.actor.ActorLogging +import akka.actor.Terminated + +object Main2 { + + def main(args: Array[String]): Unit = { + val system = ActorSystem("Hello") + val a = system.actorOf(Props[HelloWorld], "helloWorld") + system.actorOf(Props(classOf[Terminator], a), "terminator") + } + + class Terminator(ref: ActorRef) extends Actor with ActorLogging { + context watch ref + def receive = { + case Terminated(_) ⇒ + log.info("{} has terminated, shutting down system", ref.path) + context.system.shutdown() + } + } + +} \ No newline at end of file diff --git a/akka-samples/akka-sample-main-scala/tutorial/index.html b/akka-samples/akka-sample-main-scala/tutorial/index.html new file mode 100644 index 0000000000..d643ee7ee9 --- /dev/null +++ b/akka-samples/akka-sample-main-scala/tutorial/index.html @@ -0,0 +1,96 @@ + + + The Obligatory Hello World + + + + +
+

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

+ +

+Open HelloWorld.scala +

+ +

+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 receive +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 Greeter.scala. +

+ +

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

+ +

+Main.scala +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 +Main2.scala +

+ +

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

+ +
+ + + diff --git a/project/AkkaBuild.scala b/project/AkkaBuild.scala index b73358c725..5303027f20 100644 --- a/project/AkkaBuild.scala +++ b/project/AkkaBuild.scala @@ -446,7 +446,7 @@ object AkkaBuild extends Build { id = "akka-samples", base = file("akka-samples"), settings = parentSettings, - aggregate = Seq(camelSample, fsmSample, helloSample, helloKernelSample, remoteSample, persistenceSample, clusterSample, multiNodeSample, osgiDiningHakkersSample) + aggregate = Seq(camelSample, fsmSample, mainSampleJava, mainSampleScala, helloKernelSample, remoteSample, persistenceSample, clusterSample, multiNodeSample, osgiDiningHakkersSample) ) lazy val camelSample = Project( @@ -463,9 +463,16 @@ object AkkaBuild extends Build { settings = sampleSettings ) - lazy val helloSample = Project( - id = "akka-sample-hello", - base = file("akka-samples/akka-sample-hello"), + lazy val mainSampleJava = Project( + id = "akka-sample-main-java", + base = file("akka-samples/akka-sample-main-java"), + dependencies = Seq(actor), + settings = sampleSettings + ) + + lazy val mainSampleScala = Project( + id = "akka-sample-main-scala", + base = file("akka-samples/akka-sample-main-scala"), dependencies = Seq(actor), settings = sampleSettings )