Eclipse not recognizing Scala code

前端 未结 11 2669
说谎
说谎 2021-02-18 19:20

I have Eclipse Indigo with the Scala IDE plugin. I downloaded a lift project from Maven. It builds correctly. Eclipse says it is viewing it with the Scala editor.

How

相关标签:
11条回答
  • 2021-02-18 19:41

    Sometimes, or in some versions, you don't see the "Add Scala Nature" option.

    Adding it to your .project file manually should do. E.g. this project supports scala and java natures, so it will treat .java as Java, and .scala as Scala.

    <projectDescription>
      <name>myprojectname</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>
      <linkedResources> </linkedResources>
    </projectDescription>
    
    0 讨论(0)
  • 2021-02-18 19:41

    I've had this problem before as well when using Maven and Eclipse - I'll be working in the Scala perspective and everything is fine, and then at some point Indigo completely loses track of the fact that it's using Scala and is building my code with a Java compiler. No amount of fiddling with Build Path and configurations, cleaning projects or enabling the Scala nature seems to fix it.

    The only solution I've come up with so far is to use IntelliJ when I use Maven, and use Scala Eclipse plugin only when using SBT to build projects. You can try converting your Maven POM to an SBT project, but you'll have to update that every time your dependencies change. Heiko Seeberger's sbt-eclipse plugin is pretty slick.

    0 讨论(0)
  • 2021-02-18 19:46

    It may even be simpler than that, I forgot to write the package name at the top of the source file thus Eclipse neglected to see it as a Scala file.

    0 讨论(0)
  • 2021-02-18 19:46

    I was facing the same problem, because in project scala folder was not included followed following steps project -> properties -> java built path -> source -> add folder

    0 讨论(0)
  • 2021-02-18 19:51

    A couple of things I would try:

    1) Right-click on project, Configure > Add Scala Nature.

    2) In the Scala menu, Run Setup Diagnositics... > Use recommended default settings

    0 讨论(0)
提交回复
热议问题