Eclipse not recognizing Scala code
Asked Answered
B

11

19

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.

However, it is still giving my an error on each line because it is treat the code as Java (it gives errors for no semicolon, for the word "def" etc.) I tried cleaning the project and it still gives the errors.

Buehler answered 15/12, 2011 at 15:6 Comment(3)
i hope the file is called ".scala" ?Imide
One possible reason is that you installed Scala IDE 2.0 RC3 and have Groovy plugin installed. If so, update to RC4.Dreibund
Yes, the file is called Scala. I took the Scala IDE last night, so I'm pretty sure it's RC4.Buehler
C
49

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

Crackleware answered 15/12, 2011 at 15:20 Comment(2)
This caused the "red screen of death" (red squiggly lines everywhere for me. I believe it was because I edited my eclipse.ini file to increase the heap size (as recommended by the Scala plugin on startup) then restarted eclipse -- Then the setup diagnostics never re-ran, causing the Scala plugin not to never be setup correctly.Ladybug
One thing that tripped me up - you have to be in the Scala Perspective for the Scala Nature to be available.Hessian
R
8

Open the Package Explorer, look at your scala source. Does the icon displays a S (for Scala), or a J (for Java)?

If you see a S, then you are likely missing the Scala Nature. As Luigi suggested, try to add the Scala Nature and see if that fixes your issue (Right-click on project, Configure > Add Scala Nature.)

Otherwise, if you see a J, the odds are that "JDT Weaving" is not enabled. That should not happen and might depend on other plugins you have installed.

What I would try if I were you is simply uninstalling all Scala IDE plugins from Eclipse ("Scala IDE for Eclipse", and also the "JDT Weaving for Scala" if you see it in the list of installed plugins). Then, reinstall Scala IDE 2.0.0-RC04. I know, it's not the ideal solution, but it's hard to tell what is going on without more information.

If that doesn't work either, please write a message in the scala-ide-user Mailing List. Make sure to provide the full list of plugins you have in your Eclipse installation. That might help us understand what is going on.

Reflation answered 15/12, 2011 at 17:29 Comment(0)
G
7

This problem can show up when you copy an existing java project to start a new project or use a project file generator.

One thing you can look at is your Java Build Path inside project properties. Make sure your scala source folder doesn't have an include filter like **/*.java. Make sure it is **/*.scala or remove it and your source should be detected by the scala plugin.

Gally answered 1/10, 2013 at 12:8 Comment(4)
Had the same problem and only after adding included items the errors went away.Enclave
This also solved my issues, except I had no "source folders" listed at all. Creating a new folder, moving my source files into it, and then adding it as a source folder from the Java Build Path menu fixed my problem.Rooted
It's happens any time when I switch brunches (git), Do you know how to remove it forever?Glennglenna
Lifesaver. In my case the scala code was shown as scala in the package explorer and as java in the editor. The editor was acting insane, autocompletion not working, imports not working. After removing the java filter form the .classpath everything is back to normal.Spiderwort
D
2

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.

Dentilingual answered 11/1, 2013 at 17:10 Comment(0)
B
2

I solved the problem with compile/build errors with sbt-eclipse by

  1. Right-click project
  2. Scala menu -chose New Scala Installation and select version until no errors were listed
Bertine answered 3/9, 2015 at 18:6 Comment(0)
M
1

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

Monochord answered 2/11, 2015 at 9:20 Comment(1)
I think this answer was a strange way to say the problem was fixed by doing the described steps.Demibastion
L
0

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.

Licking answered 15/12, 2011 at 17:30 Comment(2)
I'm not much experienced with ScalaIDE+Maven, but I'm very surprised to hear that. I know for sure lots of folks use the Scala IDE for Eclipse with Maven, and we don't know of any such problem. What may be happening is that you regenerate the Eclipse metadata project's files, and because of that the Scala Nature is no longer added to your project. Adding the Scala Nature is very easy, simply right-click on project, Configure > Add Scala Nature. You may also be interested in m2eclipse-scala (github.com/sonatype/m2eclipse-scala).Reflation
Great! Let us know how it goes, we definitely need help to improve the User Documentation with respect to Scala IDE+Maven ;)Reflation
E
0

I have similar issues, though when I remove the Scala Nature and Add it back it becomes ok. Which is fine for now.

But there is another issue:

My Java Classes refuse to recognize my Scala ones. However when I do a "Ctrl + Click" = Open Declaration, it goes to the right place. My Java Classes that depend on Scala look like Red all over. I checked Build Path settings etc, they all look ok.

Ecliptic answered 7/5, 2012 at 3:26 Comment(0)
I
0

My Java Classes refuse to recognize my Scala ones. However when I do a "Ctrl + Click" = Open Declaration, it goes to the right place. My Java Classes that depend on Scala look like Red all over. I checked Build Path settings etc, they all look ok.

I had the same problem. When I moved my Scala classes to the correct package folder, it worked. Scala does not need this. But only that way Java editor reconized the Scala class.

Inurbane answered 24/6, 2015 at 18:15 Comment(0)
D
0

I use Maven to generate my jar. So followed the steps below Right click on project -> Maven -> Update Project -> Check force Update of Snapshots/Releases -> OK

Depend answered 16/9, 2017 at 22:59 Comment(0)
D
0

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>
Dressler answered 15/2, 2018 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.