Scala/ Eclipse - Files not compiling

2019-08-07 06:31发布

问题:

I added a Maven project with the "scala-archetype-simple" but post project creation, Scala source files are not being recognized by the compiler and i'm getting errors such as

"Syntax error on token ClassHeader expected instead"

and a lot of compilation errors saying "Java Problem"

How should this be fixed?

回答1:

"Add Scala Nature" might not be enough. after that if you don't see "Scala Library" in your project, you can right click the project and go to "Scala" menu then click "Add Scala Library to Build Path", then it would work.



回答2:

Right click on the project, select Configure -> Add Scala Nature. This fixes the problem instantly.



回答3:

It worked fine for me in Eclipse, but:

  • you need to have the m2eclipse-scala connector installed.
  • there are two scala-archetype-simple versions, make sure you're using version 1.5, in group net.alchim31.maven.