[scala-ide-user] Error "Selection does not contain a main type"

577 views
Skip to first unread message

vonforstmeyer

unread,
Apr 20, 2010, 12:18:25 PM4/20/10
to Scala IDE User
I seem to get this consistently when running a simple Scala
application from Eclipse...

Any suggestions?


--
Subscription settings: http://groups.google.com/group/scala-ide-user/subscribe?hl=en

ajo

unread,
Apr 27, 2010, 5:37:18 AM4/27/10
to Scala IDE User
same for me

I'm working with Eclipse 3.5.1 and the Scala plugin of 2.7.7

I've created a Scala project and a Scala object "Hello" with the
following code

package test

object Hello extends Application {
println("Hello")
}

When I try to start this via the context Menu: Run As -> Scala
Application (only possibility given)

I get "Selection does not contain a main type" as error

What to do ?

THANKS

Miles Sabin

unread,
Apr 27, 2010, 6:00:41 AM4/27/10
to scala-i...@googlegroups.com
On Tue, Apr 27, 2010 at 10:37 AM, ajo <andreas...@googlemail.com> wrote:
> same for me
>
> I'm working with Eclipse 3.5.1 and the Scala plugin of 2.7.7
>
> I've created a Scala project and a Scala object "Hello" with the
> following code
>
> package test
>
> object Hello extends Application {
>    println("Hello")
> }
>
> When I try to start this via the context Menu: Run As -> Scala
> Application (only possibility given)
>
> I get "Selection does not contain a main type" as error
>
> What to do ?

A couple of things ...

Unless you're absolutely tied to Scala 2.7.7, I would very strongly
recommend moving to 2.8.0 ... the Eclipse tooling has been more or
less completely redesigned and reimplemented since 2.7.x, and whilst
there's still a lot of work to do, the general consensus is that it
has very much improved as a result.

If you are tied to 2.7.7, then for your example you'll have to create
the Run Configuration manually ... navigate Run => Run Configurations
... => Scala Application, click on the "New launch configuration"
button and then specify the main class by hand.

The issue with 2.7.7 and earlier is that the mechanism for finding
main classes, which is inherited from the JDT, isn't able to reliably
detect Scala mains. In 2.8 that Just Works.

A general comment: the use of the Application trait is deprecated. You
should instead write,

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

If you do that then I think even 2.7.7 will find your main class using
plain Run As => Scala Application ... if not, use the manual method of
creating a Run Configuration I've just described.

Cheers,


Miles

--
Miles Sabin
tel: +44 (0)7813 944 528
skype: milessabin
http://www.chuusai.com/
http://twitter.com/milessabin
Reply all
Reply to author
Forward
0 new messages