configure run in eclipse for Scala

后端 未结 14 2006
自闭症患者
自闭症患者 2021-01-30 16:03

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

14条回答
  •  你的背包
    2021-01-30 16:35

    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]) {  }
    

    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!")
    }
    

提交回复
热议问题