17

I've created a Play Framework program via Typesafe Activator (so it follows the template exactly).

I used sbteclipse-plugin version 3.0.0 to create an Eclipse project and imported that into Scala IDE 4.0.0. These are all the latest versions at the time of writing.

The Scala IDE definitely seems to support the Play Framework. It has syntax highlighting for the custom formats, including the routing file and templates. Yet, it doesn't seem to be able to find the views from the controllers. In particular, the call to views.html.index triggers an error: "object index is not a member of package views.html".

enter image description here

I tried enabling refreshing using native hooks or pooling as detailed here, but it had no affect.

I should note that while the code has been compiled in the command line (with activator ~run), it hasn't been compiled in Scala IDE, since I don't know how to (it doesn't seem to be documented anywhere).

What can I do to get rid of these false errors?

EDIT: After running activator clean ~run, I have another error: The project cannot be built until build path errors are resolved. There's no further details on what these build path errors are.

Community
  • 1
  • 1
Kat
  • 4,645
  • 4
  • 29
  • 81
  • Did you ever figure it out? I'm having the same problem. Suspect the plugin does not work with 4.0 scala ide but only 3.x – user384842 Feb 11 '15 at 16:39

6 Answers6

24

Update: Just upgrade to sbteclipse version 5.1.0 and everything should work out of the box. Also make sure you follow the Play documentation on how to set up Eclipse/ScalaIDE.


This is a known bug in sbteclipse, which probably will be fixed soon.

For now, you can add the following line to your build.sbt:

EclipseKeys.createSrc := EclipseCreateSrc.All

Kill the SBT console and run sbt eclipse again. That should add the following line to the .classpath file within your project folder as a workaround:

<classpathentry kind="src" path="target/scala-2.11/twirl/main"/>

Refresh your Eclipse project to pick up the change.

mkurz
  • 2,658
  • 1
  • 23
  • 35
  • 3
    This introduces `Build path contains duplicate entry: 'target/scala-2.11/src_managed/main' for project '...'`. So although it can be manually de-duplicated from the project's java build path in eclipse, this is not really a solution as is. Also I think a project `clean` is necessary not just a refresh, when making these kind of changes. This solution is behaving quite oddly for me. – matanster Feb 27 '15 at 11:24
  • After following instructions, refreshing and rebuilding, problem remained. When I opened project -> java path, several paths, such as twirl/test and .../managed/... still said [empty] after their names. I had to delete the eclipse project and then re-import it before all java-path entries were present and the view object not found went away. – Stephen W. Wright Mar 10 '15 at 15:22
  • 2
    @matt, in case you still need it, I found a work-around for that error and posted it as a solution below. – webdevelopersdiary Apr 11 '15 at 09:08
  • Thanks! I got used to manually solving it after every `sbt eclipse` but will try if it's not solved in the next release of Play and ScalaIDE – matanster Apr 11 '15 at 09:32
  • @pitchblack408 You do not need this workaround anymore for Play 2.4.x. Just follow the guide at https://www.playframework.com/documentation/2.4.x/IDE#Eclipse to set up Eclipse, everything should work out of the box. My workaround here is just for Play 2.3.x. – mkurz Aug 10 '15 at 10:30
  • Not sure about "will be fixed soon". Amazingly it is still the case that this is not fixed in any release I can see. – matanster May 27 '16 at 17:45
  • I just updated my answer: Upgrade `sbteclipse` to version `5.1.0` (released yesterday) and everything should work out of the box now (assuming you did follow the set up instruction linked in my answer). – mkurz Jan 13 '17 at 11:45
12

I had the same issue, also with Scala IDE 4.0.0 . I followed mkurz instuctions and they worked like a charm. But instead of changing the .classpath file in the project folder manually I used Eclipse interface:

  • In the top menu of the main window, click on Project and then on Properties.
  • In the Properties window, click on Java Build Path option (options list is on the left)
  • In the Source tab, click on Add Folder... button.
  • In the Source Folder Selection window, choose the target/scala-2.11/twirl/main folder, so it is included in the compilation path. Click Ok button.
  • Click Ok in the Properties window.

Now the project should compile just fine :) . With that I was able to finish the play setup example in Scala IDE website

Community
  • 1
  • 1
Luis Rodero-Merino
  • 1,929
  • 1
  • 12
  • 8
  • 1
    Eclipse doesn't see "scala-2.11" folder under target... this is such a joke – SpaceMonkey Dec 13 '15 at 18:06
  • Please see my updated answer: Upgrade `sbteclipse` to version `5.1.0` (released yesterday) and everything should work out of the box now. – mkurz Jan 13 '17 at 11:47
4

I tried @mkurz solution first, but also ran into the same error as @matt. I became frustrated that I could not generate the eclipse project without having to go to the Eclipse project properties to manually fix the build errors. After some investigation, I discovered the solution that removed all errors entirely. Add this your build.sbt:

unmanagedSourceDirectories in Compile <+= twirlCompileTemplates.target

Or if that does not work for you, you could also use:

unmanagedSourceDirectories in Compile <+= target.zipWith(scalaBinaryVersion) { (b,v) => b / s"scala-$v/twirl/main" }

Good bye, build errors!

0

I got the same error message. Are you using java8 as jre in eclipse? After switching back from java8 to java7, everything worked fine again.

gun
  • 1,046
  • 11
  • 22
  • It was using Java 8 as the JRE, but switching it to Java 7 (and restarting) had no affect. – Kat Jan 23 '15 at 19:02
0

If, after following Mkurz' instructions (adding EclipseKeys.CreateSrc... ), your problems are not solved, click on Project -> Properties -> Java Build Path. Look at the source folders tab.

You may find a duplicate file folder named .../src_managed/main (Thanks Matt). If so, close the project. Remove ONE of the two ../src_managed/main entries from the .classpath file (located in the base of the activator/SBT project directory). Reopen and clean the project and you should be good to go.

0

For me, it turned out that installed JRE in the Scala IDE was openjdk, changed it to Oracle Java 8 and it worked.

Sayantam
  • 914
  • 8
  • 5