34
votes

I've created a play project with play 2.3.7

In the project directory, I ran activator and ran the eclipse command to generate eclipse project files.

When I go to eclipse (I'm using the Scala IDE from typesafe Build id: 4.0.0-vfinal-20150119-1023-Typesafe , there is an error in my Application.scala file:

object index is not a member of package views.html

Is there something amiss with my setup? The app runs fine when I execute run at the activation console prompt.

Thanks!

EDIT: Added code

package controllers

import play.api._
import play.api.mvc._

object Application extends Controller {

  def index = Action {
    Ok(views.html.index("Your new application is ready."))
  }

} 

The error is on the 'Ok..' line.

There is a file in views called index.scala.html, and the app runs file when I run it from activator..

11
Can you show us the code where the compiler complains?Jean Logeart
I suspect that the play2 plugin is not compatible with scala ide 4. I will try to switch to scala ide 3. stackoverflow.com/questions/28104968/…user384842
Please post your build.sbtBAR

11 Answers

28
votes

Occasionally after adding a view in Play 2.4.x, IntelliJ IDEA sometimes gets confused and absolutely refuses to build. Even rebuild Project fails:

enter image description here

This still happens from time-to-time in IDEA 15. And when it does, the command line provides the quickest, most-reliable fix:

sbt clean; sbt compile

That's it! IDEA will now compile the project as expected.

Update:

In the rare case that sbt compile completed successfully on the command line, but IntelliJ IDEA 15 still gives the same "object x is not a member" error, then this has solved IDEA's confusion:

File Menu:

enter image description here

12
votes

The other solutions did not work for me. Some would give me different errors, some would clear the Problems tab but leave me with a red squiggle under views.html.index and auto-complete would not work with the scala.html templates.

What finally worked was to open the project's properties, go to Java Build Path > Source, and add both of the following directories:

target/scala-2.11/src_managed/main
target/scala-2.11/twirl/main

If you only do target/scala-2.11/twirl/main then you'll miss out on the class files generated from the conf directory.

8
votes

In Scala IDE 4.0.0 thinks there's errors in an out-of-the-box Play Framework 2.3.7 program you can find the solution (in brief: adding target/scala-2.11/twirl/main folder to the compilation path), give it a try.

4
votes

I had the same problem. I added target/scala-2.x/classes and target/scala-2.x/classes_managed to my Java build path and Eclipse stopped complaining.

2
votes

Adding target/scala-2.11/twirl/main which is having views.html package to source fixed for me.

2
votes

I had the same issue running Play 2.4.0-RC1 using default SBT layout (disablePlugins(PlayLayoutPlugin)) and solved it by adding to build.sbt:

sourceDirectories in (Compile, TwirlKeys.compileTemplates) :=
    (unmanagedSourceDirectories in Compile).value
1
votes

@brent-foust 's answer worked for me but only initially. Every time I rebuilt the project from within IDEA I would then get "not found: routes" errors from within target\scala-2.11\twirl\main\views\html\main.template.scala until I performed Brent's workaround again.

I eventually discovered the solution to that was changing a line in the .iml file from

<excludeFolder url="file://$MODULE_DIR$/target/scala-2.11/src_managed/main" />

to

<sourceFolder url="file://$MODULE_DIR$/target/scala-2.11/src_managed/main" isTestSource="false" />

I don't know what the long term implications of doing this are but it has fixed this problem. Some of the other similar problems mentioned might also be fixed by applying the same change to some of the other folders listed in the .iml.

1
votes

I tried all solutions without any positiv result.
So I went to Preferences > Build, Execution, Deployment > Build Tools > sbt and checked Use sbt shell for imports and builds.
This let the compile button in intelliJ compile with the sbt shell. I think this is better anyway, since a build server or something similar will compile the same way and not like intelliJ.

0
votes

For me when importing the project into intellij making sure I "checked" the "auto import" checkbox did the trick.

0
votes

1) Add the following line to your sbt.build file:

EclipseKeys.preTasks := Seq(compile in Compile)

2) Add the follwing line to your plugins.sbt file under the project folder:

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.1.0")

3) Run the "eclipse" command from within sbt

as explained in the documentation of the play framework:

Setting up your preferred IDE

0
votes

Basically we need a way to put the compiled classes on the path for this to work.

I did the following to fix it. Since the projects compiles to the target directory. I went to the Project Properties -> Java Build Path and added a few folders that look like this,

target/scala-2.12/routes/main target/scala-2.12/twirl target/scala-2.12/twirl/main

Now i dont want you to assume you will have these exact folders in your case too. That depends on your project setup. But you should add the folders inside the target/scala-2.x folder.