سؤال

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>
هل كانت مفيدة؟

المحلول

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>

نصائح أخرى

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.

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

I was having the same issue. I'm using Eclipse 4.3 (Kepler) and
Scala IDE for Eclipse 3.0.1.v-2_10-201307101641-eff8147. I have a maven scala project that I eclipsified and imported. It was working just fine, but when I import java packages, the whole file is no longer compilable. I was able to get it to compile again by changing the order of the libraries. But then that trick no longer worked and all of my scala files become uncompilable. I tried all of the things suggested here (the Eclipse dance) to no avail.

Then I tried creating a new scala project in Eclipse. I copied over the .classpath file and the src directory from the original project - et voila! Now it compiles just fine. There must be a problem in the maven-generated eclipse files.

ETA: I checked my .project file created by maven. It had this specified in it: <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> </buildCommand>

And when I took it out, the problem disappeared. I also had another problem: <comment>myproject. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>

Which is probably why the javabuilder appeared in the first place. I had to add in the scalabuilder by adding Scala Nature to my project. Maybe this problem won't appear of I add the M2Eclipse plugin. I will try it and see.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top