derek derek - 3 years ago 123
Scala Question

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

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

Answer Source

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)
)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download