7

I'm having a little trouble (more like an annoyance, really) when using the Play Framework with Eclipse.

I'm following this tutorial to get started with Play. In a certain moment in the tutorial, it asks us to type in this code:

public static Result index() {
  return redirect(routes.Application.tasks());
}

This works as expected when running the application. The problem is that Eclipse doesn't like it. It says:

The method tasks() is undefined for the type ReverseApplication

While underlining tasks with the dashed red line. Is there a reason for this to happen? I've tried cleaning and compiling the project (through the Play terminal) and refreshing the project in Eclipse, but to no avail.

Is there something I can do about it?

I'm using Eclipse Juno, build 20120606-2254

Thank you so much!

biesior
  • 55,576
  • 10
  • 125
  • 182
Victor Girotto
  • 113
  • 1
  • 5

5 Answers5

10

Since the views are Scala code, they are compiled by the Scala compiler (ie your Play console through sbt). So Eclipse cannot compile and find these.

So, your best option is to configure Eclipse so that it automatically refresh the workspace and make sure that the folder "target/scala-2.9.1/classes_managed" is in your build path (it should be done by the "eclipsify" command).

If it does not work after all these steps, try "clean", "compile" and "eclipsify" (for Play 2.0.x) or "eclipse" (for Play 2.1.x) and refresh your projet.

Community
  • 1
  • 1
ndeverge
  • 21,378
  • 4
  • 56
  • 85
  • 2
    Awesome! Running "clean", "compile", "eclipsify" and refreshing the project did it. The weird thing it that the "target/scala-2.9.1/classes_managed" directory was already on the build path. Anyway, problem solved. Thank you! :) – Victor Girotto Jun 24 '12 at 22:49
  • Similar result. I ran "play clean then play compile, and finally "play eclipse" and that did the job for me. "Eclipsify" did not work for me on on version 2.1 – Marco RS Feb 16 '13 at 08:51
  • Yes, it has been replaced with "eclipse" in Play 2.1. I updated the answer. Thanks for the pointer :-) – ndeverge Feb 16 '13 at 10:52
6

Close and open your project in Eclipse. This worked for me (Eclipse Juno).

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
bsmk
  • 1,307
  • 1
  • 14
  • 26
2

None of the previous suggestions worked for me, but when I did a refresh on the target folder, the red underlining on my view references went away.

Michael Szczepaniak
  • 1,970
  • 26
  • 35
1

The Play command used to be called "eclipsify". It is now called "eclipse".

Generally, I do the following and it works pretty well with Eclipse

-at the start of the day, start the play console in your project dir and do 'clean' and 'run'  
-open a web browser point to the app (localhost:9000)  
-launch eclipse  
-make code changes...  
-Play will rebuild the app whenever code changes occur. So refreshing the app in
   the browser.  
-back in eclipse, Refresh the project to reload the files that play rebuild just made.
IanRae
  • 293
  • 1
  • 2
0

I know it has been a year since @nico_ekito's answer but just wanted to add this. Adding /target/scala-2.10/classes_managed and ensuring that Eclipse automatically refreshes the workspace fixed it for me. Thanks @nico_ekito

Using Eclipse Kepler, play framework 2.2.2

geekay
  • 215
  • 2
  • 7