Alex Rivera | Logout

configure run in eclipse for Scala

Asked 2010-12-09T13:26:37.053
60

I am a beginner in Scala. I installed Scala IDE in eclipse and now I want to run my application programme. It never shows "run as Scala application", instead it shows "run as Java application" or "Java applet"

I opened "run configuration" and clicked on "Scala application" and my project name is "test" and second column is of "Class Main". What do I have to fill in? I filled in "Main.Scala", but it states "could not find mainmain class main.scala".

Can you help me with running this project?

Edit
Report

1 Answer

50

If you want to run the whole project it should have a "main class", in any of your Scala objects you should be defining:

def main(args:Array[String]) { <some nice code here> }

From there it should be "calling" the rest of your objects to do whatever the whole project does and in the "Class Main" column you should specify the fully qualified name of your object. For instance, if you defined the main in a class called "Start" in the package "starter", in the "Class Main" field you should state "starter.Start".

But on the other hand if you only want to run a Scala object it should extend App, if it doesn't extend App, Scala IDE won't add the "Run as Scala Application...":

package greeter
object Hello extends App {
  println("Hello, World!")
}
answered 2012-09-13T10:10:27.167

Your Answer