Asdf11
Asdf11

Reputation: 447

Scala Main Class not found in Eclipse ide

I installed scala and scala IDE for eclipse. I get this message everytime I try to compile a simple "HelloWorld":

package asd

object testobject {
  def main(args: Array[String]): Unit = {
    println("asda");
  }
}

"Error: Mainclass asd.testobject could not be found"

New Scala Project -> asd

New Scala Object -> Copy&Paste the code above

Run As -> Scala Application

My problem is that I've tried literally everything I found on the internet and it wont work. I really dont know why it doesnt work. Main class in Runconfig: asd.testobject. I really hope that anyone of you can help me, I think I didnt include the environment or scala jre somewhere...??

scala -version : 2.11.6

EDIT:: @dragonborn I'm not quite sure what do you mean? I made a picture which shows my config for scala. Can you explain it?

I cannot post pictures here so here is the Link: scala config

Upvotes: 4

Views: 6472

Answers (5)

Peluo
Peluo

Reputation: 11

If your scala source has a main Object like this:

package org.xx.yy

object MyPackage extends App {
}

Then in Eclipse IDE set "Debug configurations->Scala Application->Main class" to "org.xx.yy.MyPackge"

Upvotes: 0

user4322779
user4322779

Reputation:

I just did a complete installation of Eclipse and the Scala IDE for Eclipse, created a runnable scala object using it and ran that object to produce the expected output with no problems. My installation platform is Windows 7 x86_64. This is what I did:

  1. downloaded eclipse-jee-luna-SR2-win32-x86_64.zip from Columbia University at the Eclipse downloads - mirror selection page at https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/luna/SR2/eclipse-jee-luna-SR2-win32-x86_64.zip

  2. unbundled the download and updated its eclipse.ini file with -Xms256m and -Xmx2048m

  3. created a new workspace folder

  4. started eclipse by double clicking on eclipse.exe in the folder of the unbundled download and entered the pathname of the new workspace folder in its Workspace Launcher's Select a workspace pop-up when it became available

  5. in the running eclipse selected Help > Install New Software... to get the Available Software pop-up, clicked on Add in it to get the Add Repository pop-up and in that added the URL for the Scala IDE for Eclipse4.4 (Luna) For Scala 2.11.6 provided at http://scala-ide.org/download/current.html (the IDE repo URL is http://download.scala-ide.org/sdk/lithium/e44/scala211/stable/site) giving it the name "Scala IDE for Eclipse4.4 (Luna) For Scala 2.11.6" and clicked OK.

  6. in the resulting Available Software pop-up selected everything visible (Scala IDE for Eclipse, Scala IDE for Eclipse Development Support, Scala IDE for Eclipse Source Feature, Scala IDE Plugins (incubation) and Sources), clicked on Next and clicked on Finish

  7. after the installation finished it was required to restart Eclipse so I did that

  8. after the restart finished, in the running eclipse opened the scala perspecive by selecting Window > Open Perspective > Other > Scala

  9. created a new scala project by selecting File > New > Scala Project, giving it the name "HelloWorld" and clicked on Finish

  10. in the HelloWorld project right clicked on src and selected New > Package, entered "tn" and clicked on Finish

  11. right clicked on the tn package in HelloWord/src, selected New > Scala Object, gave it the name "HelloWorld" and clicked on Finish

  12. in the editor window of the HelloWorld object that came up, added "extends App" to the object's definition and println("hello world") in its body. Here are the contents of the HelloWorld.scala file:

    package tn
    
    object HelloWorld extends App {
      println("hello world")
    }
    
  13. ran the HelloWorld object by right clicking in its editor window and selecting Run As > Scala Application which caused "hello world" to be printed in the Console view

Upvotes: 0

Thiago Pereira
Thiago Pereira

Reputation: 1712

I do not use eclipse, but have you tried this way?

object Test extends App { println("hello world") }

Upvotes: 0

tddmonkey
tddmonkey

Reputation: 21184

Your class isn't set as a class that can be launched.

You need to extend App and put the body of your code directly in the class, like this:

package asd

object testobject extends App {
    println("asda");
}

Upvotes: 0

Dragonborn
Dragonborn

Reputation: 1815

Though it is Scala IDE :) it still expects the class scala file to be found in the right package dir.

e.g. testobject.scala should be part of src/main/scala/asd

We too had to change the scala file location for our app Main class to be able to debug it in Scala IDE. Small nuisance.

Upvotes: 3

Related Questions