Scala IDE (Eclipse) Run as Scala Application
Asked Answered
S

4

14

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!

Sosna answered 30/11, 2013 at 12:34 Comment(0)
S
7
  1. Right click on the scala object having main method
  2. Choose Run As -> Run Configurations
  3. Double click on Scala Application from Run Configurations window
  4. Type the Object Name in the Main Class: (for eg: if HelloWorld.scala is the object having main method, give it as HelloWorld)
Sulphurize answered 27/11, 2014 at 10:12 Comment(1)
And should I "type the Object Name" for every single project? Awesome!Northumberland
P
3

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 already created 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 sbt project, 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.
Polychaete answered 30/11, 2013 at 12:52 Comment(3)
Thanks for clarifying, but how might I go about creating an appropriate main object with a main method?Sosna
In my case the problem was that I copied some files (notably Main.scala) from one my previous projects and forgot to rewrite the "package ..." part of the program.Scutiform
@FilipB.Vondrášek It was the exact same problem for me as well!Factitive
P
3

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

Pastorate answered 23/2, 2014 at 11:9 Comment(0)
D
0

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

Deadhead answered 7/3, 2015 at 9:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.