no main class detected

42 views
Skip to first unread message

archsky

unread,
Feb 2, 2016, 11:52:05 PM2/2/16
to scala-user
while trying to run a very minimal helloworld from sbt documentation

object Hi {
  def non_main = println("main is a method, not a class")
}

sbt run said

[error] (compile:run) No main class detected.

But clearly, main is a method.

o_O ?

Jason Zaugg

unread,
Feb 2, 2016, 11:58:43 PM2/2/16
to archsky, scala-user
object Hi {
  def main(args: Array[String]): Unit = { println("this is an executable class") }
}

Or, with a shorthand:

object Hi extends App {
  println("this is an executable class")
}

-jason

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

archsky

unread,
Feb 3, 2016, 11:16:42 AM2/3/16
to scala-user
Oops. I think I didn't communicate the point well.
My thing was with the response that the sbt console gives, in which it refers main as a class, while main is a method. Maybe sbt console should say, something like, no main method detected.
Reply all
Reply to author
Forward
0 new messages