views:

67

answers:

2

Hi all,

I have installed Eclipse 3.5.2 and today's Scala plugin from /update-current (that's Scala 2.8 final.) I can compile and run Scala projects consisting of a single singleton object that implements main().

But, if a project contains more classes, I receive the "Could not find the main class" error.

I have tried searching for the solution and I discovered:

Eclipse is correctly looking for the Main$ class, not the Main class
* under Debug Configurations, my main class is correctly identified as mypackage.Main
* my plugin is up to date and recommended for my version of Eclipse
* cleaning, restarting etc. doesn't help.

The same project will compile with scalac.

Thanks for any ideas on how to solve this.

EDIT: MatthieuF suggested I should post the code.

This snippet produces an error. It's not the most idiomatic code, but I wrote it that way to test my environment. I tried it as a single file and as separate files. It DOES work with scalac.

import swing._

class HelloFrame extends Frame {
        title = "First program"
        contents = new Label("Hello, world!")
}

object Hello {
  val frame = new HelloFrame    
  def main(args : Array[String]) : Unit = {
        frame.visible = true
   }
}

BUT, if I nest the definition of HelloFrame within Hello, it works. This snippet runs perfectly:

import swing._

object Hello {

    class HelloFrame extends Frame {
        title = "First program"
        contents = new Label("Hello, world!")
    }

    val frame = new HelloFrame

    def main(args : Array[String]) : Unit = {
        frame.visible = true
    }
}
+2  A: 

One possibility is that you are trying to launch using ctrl-F11, but from a different class.

The Scala Eclipse plugin does not obey the defaults for Java launching. In Preferences->Run/Debug->Launching, there are some options Launch Operation->Always Launch the previously selected application, etc. This currently does not work in the Scala eclipse plugin. To launch a specified main, you need to launch it from the editor for the class.

There has been a bug raised for this. http://scala-ide.assembla.com/spaces/scala-ide/tickets/1000023-scala-launch--does-not-follow-jdt-behaviour

MatthieuF
I'm launching with Alt-Shift-X, S or alternatively by right-clicking the object implementing main() in the Package Explorer and selecting Run As/Scala Application. Unfortunately,the problem remains.
Thomas Heywood
A: 

Make sure that the .class files exist, usually below the bin directory.

In particular, if you have errors in unrelated files in the same project then the compilation may fail, and no .class files will be produced.

starblue
No, I don't see .class files. I expected this, as compilation failed with "Could not find the main class" message.
Thomas Heywood
The 'Could not find the main class' is not a compiler error. It's an error from Eclipse. If the compilation was working, there would be class files there. Try closing the project and/or cleaning. Have you got the Build Automatically checked
MatthieuF
Yes, Build Automatically is checked. Cleaning or restarting doesn't solve the problem.
Thomas Heywood