SBT error: java.lang.RuntimeException: No main class detected

11,805

Solution 1

If you want to use Actor in Scala, you need include the library, as the following:

libraryDependencies <++= scalaVersion(v =>
  Seq("org.scala-lang" % "scala-actors" % v)
)

Solution 2

Try this in your build file:

mainClass in (Compile,run) := Some("pingpong")

Solution 3

I have this exception if I try to use class instead of object.

//class Foo extends App {
//    print("No main class detected")
//}

object Foo extends App {
    print("Hello World")
}
Share:
11,805
derek
Author by

derek

Updated on June 05, 2022

Comments

  • derek
    derek almost 2 years

    Update:
    I need put libraryDependencies for using Actor in Scala.

    libraryDependencies <++= scalaVersion(v =>
      Seq("org.scala-lang" % "scala-actors" % v)
    )
    

    when I ran "sbt run", I could successfully pass the compilation but then failed on run the code.

    Here is the error: java.lang.RuntimeException: No main class detected.

    The weird thing is when I do not use SBT, I can run it without any issue:

    >scalac actor.scala
    >scala pingpong
    

    Any idea why this happens?

    I am using SBT 0.13.0 Scala version is 2.10.2

    Thanks

    Deryk.

    Here is my code:

    import scala.actors.Actor
    import scala.actors.Actor._
    
    case object Ping;
    case object Pong;
    case object Stop;
    
    class Ping(count:Int, pong:Actor) extends Actor
    {
        def act()
        {
            var counter = count -1 ;
            pong ! Ping;
            loop
            {
                react
                {
                    case Pong =>
                    if( (counter < count) && (counter > 0) ) {Console.println(counter+"->Ping: pong"); pong ! Ping; counter = counter -1;} 
                    else {pong ! Stop;exit()}
    
                }
            }
        }
    }
    
    class Pong extends Actor
    {
        def act()
        {
            loop
            {
                react
                {
                   case Ping => {Console.println("Pong: Ping"); sender ! Pong;}
                   case Stop => {Console.println("Ping Pong Communication is done!");exit()}
                }
            }
        }
    }
    
    object pingpong
    {
        def main(args: Array[String])
        {
            println(util.Properties.versionString)
            val pong = new Pong
    
            val ping = new Ping(5, pong)
    
            ping.start
            pong.start
        }
    }