configure run in eclipse for Scala

EclipseScala

Eclipse Problem Overview


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?

Eclipse Solutions


Solution 1 - Eclipse

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

Solution 2 - Eclipse

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

Solution 3 - Eclipse

make sure your declared package in your source code matches the directory structure under your source directory.

in this case, a sourcefile declaring package "greeter" will auto-run as scala if the source file is indeed under src/greeter/Hello.scala (and not just under src/Hello.scala)

Its a common mistake that doesn't get highlighted by the syntax checker.

Solution 4 - Eclipse

If you installed Scala plugin for Eclipse, open the Scala perspective. Then right-click on your project and select "Add Scala Nature" in "Configure" menu.

You should now be able to run your Scala applications.

Solution 5 - Eclipse

Download from this link Scala IDE

Restart Eclipse, create Scala Project, then create Scala Object and type this.

 package greeter

    object Hello {
    	def main(args:Array[String]) { 
    	  println("Hello, World") 
    	}	
    }

Run as Scala Application

Solution 6 - Eclipse

If it is the first time you run the Scala IDE for eclipse after setting it up and creating your project, all the thing you need is to just save your project and restart the IDE. At the next start, the "run as Scala Application" is appeared and can be used.

Solution 7 - Eclipse

I had issues with the Scala IDE for Eclipse running Scala applications that extend Application, but running objects with a proper main method, i.e. def main(args:Array[String]) {/*...*/} always works fine for me.

Solution 8 - Eclipse

Right click on the Project --> Click on Run Configurations --> In the Run Configurations window select the "Scala Application"

Run Configurations Window

Solution 9 - Eclipse

I was having similar issue. Make sure your java and scala files are not in the same package. I changed the package names and it worked for me

Solution 10 - Eclipse

Unless you have a strong reason why you need Eclipse, could I recommend that you try IntelliJ?

Version 10 was just released earlier today, and the (free) community edition is perfectly happy working with the IntelliJ Scala plugin.

Solution 11 - Eclipse

Just a pointer .. I had faced same difficulty . Being experienced from JAVA , instead of creating a Spark object I was creating spark class that why I was not getting this option .

Hope my experience helps .

Solution 12 - Eclipse

Try to run the eclipse command of the sbt tool inside your project directory, this will build your scala project for the eclipse IDE. Then you will have no problem to configure your run configuration, It might even be done for you automatically.

    $ sbt
    > eclipse 
    [info] About to create Eclipse project files for your project(s).
    [info] Updating {file:/...path-to-your-project}root...
    [info] Resolving jline#jline;2.12.1 ...
    [info] Done updating.
    [info] Successfully created Eclipse project files for project(s):
    [info] your-project-name

done! now import your project into Eclipse's workspace

Solution 13 - Eclipse

I had this issue using an Eclipse Luna Scala IDE. No of the above solution made it possible to compile my Main.scala file.

package main.scala

object Main {
  def main(args: Array[String]){
    println("Hello, I am the main object")
  }
}

The problem was the following: My project only referenced the JRE System library but no Scala library. I carried out the following steps:

  1. Right click on project properties
  2. Java Build Path
  3. Check if the Scala library is missing
  4. Click "Add Library..."
  5. Add the desired Scala library that should have been shipped with the Scala IDE.

Then, go to the Main.scala file that is lying somewhere in your project folder and contains your main function. If you right-click file, "Scala Application" should appear under "Run as".

Solution 14 - Eclipse

Following are the steps that I took to successfully run scala(Ubuntu) on eclipse:

  1. Download Scala IDE

  2. After installation, create a maven project.

  3. right click on the project, go to configure and "Add Scala Nature"

  4. In the .pom I provided the following dependencies:

     <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core -->
    

    org.apache.spark spark-core_2.12 2.4.1

     <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-sql -->
    

    org.apache.spark spark-sql_2.12 2.4.1

    org.apache.spark spark-graphx_2.12 2.4.1

  5. Ensure that src/main/scala is on the build path.

  6. Create a scala file to test your project.

Hope this helps!!!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionraghavView Question on Stackoverflow
Solution 1 - EclipseLMDDGTFYView Answer on Stackoverflow
Solution 2 - EclipseRajgopal CView Answer on Stackoverflow
Solution 3 - EclipseRam JanovskiView Answer on Stackoverflow
Solution 4 - EclipsejopasseratView Answer on Stackoverflow
Solution 5 - Eclipsejimakos17View Answer on Stackoverflow
Solution 6 - EclipseSerendipityView Answer on Stackoverflow
Solution 7 - EclipseFabian SteegView Answer on Stackoverflow
Solution 8 - EclipsesparkDabblerView Answer on Stackoverflow
Solution 9 - EclipsenirView Answer on Stackoverflow
Solution 10 - EclipseKevin WrightView Answer on Stackoverflow
Solution 11 - EclipseSandeep DasView Answer on Stackoverflow
Solution 12 - EclipseJules0707View Answer on Stackoverflow
Solution 13 - EclipseMichaelHuelsenView Answer on Stackoverflow
Solution 14 - Eclipseprashant.kr.modView Answer on Stackoverflow