为Scala配置在eclipse中运行 [英] configure run in eclipse for Scala

查看:94
本文介绍了为Scala配置在eclipse中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Scala的初学者。我在eclipse中安装了Scala IDE,现在我想运行我的应用程序。它从不显示以Scala应用程序运行,而是显示以Java应用程序运行或 Java小程序

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"

我打开了运行配置并单击 Scala应用程序,我的项目名称是 test,第二列是 Class Main。我必须填写什么?我填写了 Main.Scala,但状态为找不到mainmain类main.scala。

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?

推荐答案

如果要运行整个项目,它应该有一个主类,在您的任何Scala对象中都应定义:

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> }

从那里应该调用其余对象来完成整个项目的工作在 Class Main列中,应指定对象的完全限定名称。例如,如果您在 starter包中的 Start类中定义了main,则应在 Class Main字段中声明 starter.Start。

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".

但是,另一方面,如果您只想运行一个Scala对象,则应扩展App;如果不扩展App,则Scala IDE不会添加运行为Scala应用程序...:

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

这篇关于为Scala配置在eclipse中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆