Scala Nature in Eclipse

Since I’ve been trying to have Scala help with simplifying Java code, I’ve been looking into the possibility of having java and scala classes in the same project(under netbeans and Eclipse). While Netbeans doesnt seem to have this functionality available yet,  someone pointed out the “scala nature” functionality in Eclipse.

Basically, if you have a Java project, you can do a right click -> Scala -> Add Scala Nature. Doing so puts the scala libraries on the classpath and converts the project to a Scala project. This is supposed to allow one to have both Java and scala code in the same project and have them refer to each other.
I’ve been trying this. Here’s what I have:
1.  Scala objects are not visible from java classes, only scala classes are, this is apparently a known problem. I dont see why it would a problem allowing the access of the object’s methods like one would access static methods in Java.
2. When I right click -> Scala -> add Scala Nature for a JavaEE project, it does not add the scala libraries to the project classpath. So this does not solve my problem of having Scala code in Java Web apps.
3. So adding Scala nature only works for regular Java Projects for now.

Its a start though, and if we can access Scala objects and have JavaEE web apps which scala code in them, it’ll bring us one step closer to JavaEE nirvana :-).

Advertisements

7 thoughts on “Scala Nature in Eclipse

  1. Hi,
    I’ve recently experienced the same problem, whereas this used to work before (with the old plugin) :
    http://blog.developpez.com/djo-mos/p5399/java/scala/ajouter-le-support-scala-a-un-projet-web/
    and :
    http://blog.developpez.com/djo-mos/p5428/java/wicket/wicket-et-scala-voici-ce-que-ca-donne/

    (the two blog posts are in french, but the screenshots should be universally understood :D)

    I’m glad to see that I’m not alone in the world 😉

    Cheers

  2. Hi, I just wanted to note that with a new version of Eclipse and a new version of the Scala IDE plugin, the command to add a Scala nature is:

    right click -> Configure -> Add Scala Nature

    Thanks for the tips!

  3. Argh. This sort-of works, but before even adding a single Scala class, about 1 in 5 of my Java classes throw errors as soon as the Scala Nature is added on imports with messages like:
    MyInnerClass is not a member of _root_.my.package.MyClass

    for imports like:
    import my.package.MyClass.MyInnerClass

    The same thing happens with most ‘import static’ statements.

    Ugh. (Helios, 2.8.1). There are bugs filed against the eclipse plugin, but all are dismissed as not reproducible, even if there is a complicated repro case.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s