« Return to Thread: main method in file with class and object?

main method in file with class and object?

by John Tyler-2 :: Rate this Message:

Reply to Author | View in Thread

Hello, I'm trying to verify some behavior I've seen.  I defined a file MyApp.scala as such:
class MyApp {
  // blah
}

object MyApp {
  def main(args: Array[String]) {
    val app = new MyApp
    // blah
  }
}

I then compiled with "scalac MyApp.scala", but when I run with "scala MyApp" from the same directory I get:
java.lang.NoSuchMethodException: MyApp.main([Ljava.lang.String ;)

The only way I've been able to get this application to start is by declaring the object MyApp in a separate file with nothing else in it.  (I want to use command-line arguments so haven't tried this particular case with object MyApp extends Application.)  I've checked the ScalaReference.pdf, "Programming in Scala" book from Odersky et al, this mailing list's archives, and Google for some confirmation that this is indeed required but so far no luck.  In fact I have found a number of places mention something similar to this excerpt from "Programming in Scala":
Any singleton object with a main method of the proper signature can be used as the entry point into an application.

My Java and Scala versions are below, I'm running Ubuntu 7.10.  Any ideas?

Thanks!
John

java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Server VM (build 1.6.0_03-b05, mixed mode)

Scala code runner version 2.6.1-final -- (c) 2002-2007 LAMP/EPFL

 « Return to Thread: main method in file with class and object?