Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

configure run in eclipse for Scala

Tags:

eclipse

scala

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?

like image 823
raghav Avatar asked Dec 09 '10 13:12

raghav


People also ask

Can we run Scala on Eclipse?

The command below will make the project eclipse compatible and you will be able to import this project in eclipse and run it successfully. Select root directory helloworld. You can now see that you can import this project by clicking on Finish. Now, let's run it as Scala application.

How do I run Scala IDE?

Launching and Debugging scalac To launch scalac from Eclipse you need to create a Run Configuration, from Run → Run Configurations. Choose Scala Application and set the main class to scala. tools.


2 Answers

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!") } 
like image 180
LMDDGTFY Avatar answered Oct 29 '22 14:10

LMDDGTFY


Right click your project and check the "Scala Compiler" settings. Check the "Project Specific" checkbox and try checking if you can run your Scala object (which should extend App).

like image 30
Rajgopal C Avatar answered Oct 29 '22 14:10

Rajgopal C