Java Scala IDE (Eclipse) 作为 Scala 应用程序运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20300300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 00:56:27  来源:igfitidea点击:

Scala IDE (Eclipse) Run as Scala Application

javaeclipsescalascala-ide

提问by user3052079

I'm relatively new to the scala language (and programming in general). I recently installed the JDK and the Scala IDE (for eclipse). The setup went smoothly, but I encountered an issue upon trying to run a Hello World application. When I attempt to "Run As" the only available options are "Java Applet" and "Java Application". How do I proceed in trying to run as a "Scala Application"? Many thanks in advance!

我对 Scala 语言(以及一般的编程)比较陌生。我最近安装了 JDK 和 Scala IDE(用于 Eclipse)。设置进行得很顺利,但我在尝试运行 Hello World 应用程序时遇到了问题。当我尝试“运行身份”时,唯一可用的选项是“Java Applet”和“Java 应用程序”。我如何继续尝试作为“Scala 应用程序”运行?提前谢谢了!

回答by Robin Green

Make sure you have done all of the following steps:

确保您已完成以下所有步骤:

  1. Switch to the Scala perspective
  2. Make sure the project is registered as a Scala project, not a Java project or any other kind of project. When you create the project, you can do this with New -> Scala project. If you have alreadycreated or imported the project, you can right-click on the project's root directory, then choose Scala and then Add Scala Nature. Alternatively, if it's an sbtproject, you can use the sbt-eclipse plugin for sbt to generate an Eclipse project configuration for your existing project, and then reload the project in Eclipse.
  3. Create an appropriate main object with a main method, if you don't already have one.
  1. 切换到 Scala 透视图
  2. 确保项目注册为 Scala 项目,而不是 Java 项目或任何其他类型的项目。创建项目时,您可以使用New -> Scala project. 如果您已经创建或导入了项目,您可以右键单击项目的根目录,然后选择 Scala,然后添加 Scala Nature。或者,如果是sbt项目,你可以使用sbt的sbt-eclipse插件为你现有的项目生成一个Eclipse项目配置,然后在Eclipse中重新加载该项目。
  3. 如果您还没有一个 main 方法,请使用 main 方法创建一个适当的 main 对象。

回答by tse

Try to click right button on the Scala object with mainmethod (not on the root project element). Then the "Run as... Scala application" menu item appears.

尝试使用main方法在 Scala 对象上单击右键(而不是在根项目元素上)。然后出现“作为... Scala 应用程序运行”菜单项。

回答by ajesh kumar

  1. Right click on the scala object having main method
  2. Choose Run As-> Run Configurations
  3. Double click on Scala Applicationfrom Run Configurationswindow
  4. Type the Object Name in the Main Class: (for eg: if HelloWorld.scala is the object having main method, give it as HelloWorld)
  1. 右键单击具有 main 方法的 scala 对象
  2. 选择Run As->Run Configurations
  3. Scala ApplicationRun Configurations窗口双击
  4. Main Class: 中输入对象名称(例如:如果 HelloWorld.scala 是具有 main 方法的对象,则将其指定为 HelloWorld)

回答by Leon Rom

I did make the main class in Java and simple call previously renamed "main in Scala". After this both @Run As@ and @Export@ works fine

我确实在 Java 中创建了主类,并且简单调用以前重命名为“在 Scala 中的 main”。在此之后@Run As@ 和@Export@ 工作正常