0

我正在关注http://doc.akka.io/docs/akka/2.2.0/AkkaScala.pdf的 akka 教程,下面是 HelloWorld 程序。主要方法是我添加的,但是当我尝试运行它时,我没有在 Eclipse 中收到“作为 Scala 应用程序运行”。根据从命令行运行程序的文档:“java -classpath akka.Main com.example.HelloWorld”,但我需要从 Eclipse 运行它,所以添加了我自己的 main 方法。为什么下面的代码不会运行?

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)
  }

  object Greeter {

    def main(args: Array[String]) {
      new HelloWorld
    }   

    case object Greet
    case object Done


  }
  class Greeter extends Actor {
    def receive = {
      case Greeter.Greet =>
        println("Hello World!")
        sender ! Greeter.Done
    }
  }


}
4

1 回答 1

2

A main method has to be within a standalone object. Here you have it within an object within a class.

于 2013-08-03T02:44:02.333 回答