Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

scala

build

sbt

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
    }
}
like image 873
derek Avatar asked Oct 20 '25 01:10

derek


1 Answers

Try this in your build file:

mainClass in (Compile,run) := Some("pingpong")
like image 155
Vidya Avatar answered Oct 22 '25 19:10

Vidya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!