Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala source files not recognized by compiler in Eclipse

I am working on a playframework project that I have eclipsified from the console and opened from Eclipse.

However my scala source files are treated as java source files by Eclipse with the resulting compilation errors.

Can anyone please help?

EDIT: My .project file:

<projectDescription>
  <name>web</name>
  <buildSpec>
    <buildCommand>
      <name>org.scala-ide.sdt.core.scalabuilder</name>
    </buildCommand>
  </buildSpec>
  <natures>
    <nature>org.scala-ide.sdt.core.scalanature</nature>
    <nature>org.eclipse.jdt.core.javanature</nature>
  </natures>
</projectDescription>
like image 824
balteo Avatar asked Mar 20 '12 11:03

balteo


3 Answers

The official supported version for Scala-ide is Helios, the Indigo version is still classed as experimental. However, you could try adding Scala Nature to your project. Right click on the Project, Select Configure->Add Scala Nature, or look at the ideas in one of the two questions I've linked to.

like image 134
Matthew Farwell Avatar answered Nov 01 '22 01:11

Matthew Farwell


I have had similar issues in the past. I think the problem was the Java Builder for the project. This is the content of a .project file that can build Java as well as Scala classes. You can compare it to your own configuration:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>debug-s</name>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.scala-ide.sdt.core.scalabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.scala-ide.sdt.core.scalanature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>
like image 4
Joe23 Avatar answered Nov 01 '22 00:11

Joe23


I went through the same issue yesterday, TWICE, in a project that was working just fine (so my project natures were fine). Both were triggered by running Maven from Eclipse with the eclipse:eclipse goal (to add references to new jars), which changed around my .classpath file and made all my .scala files red. Reverting .classpath to match my previously-working version (minus the new jars) wouldn't fix the compile errors. I restarted Eclipse, rebuilt, cleaned, pulled the Java and Scala natures in and out of the .project file, diffed everything against versions that had worked an hour before... still all red. Very frustrating.

I don't remember exactly what combination of those steps fixed things the first time yesterday, but just now I came in, did the clean, restart, etc, still all the Scala files are broken. Sigh. Then "hmmm" and I edited one of the .scala files. THAT triggered a "real" build, and now everything is fine. ?!?!?

TL;DR if your project was fine previously, and now ALL your .scala files are broken, try making a trivial edit to one of them, it worked for me

like image 2
Rodney Gitzel Avatar answered Nov 01 '22 02:11

Rodney Gitzel