8

I'm a beginner user of Play Framework 2.1.3 and I have just created a new Java application and I have run play eclipse to generate the eclipse project for it. I have also tested so that it works by doing a play run.

So I'm following this tutorial and there is a step where you should add this piece of code:

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

But I'm getting the message "routes cannot be resolved". I have also tried play compile and in Eclipse doing a clean to no avail.

Peter Warbo
  • 11,136
  • 14
  • 98
  • 193
  • possible duplicate of [Play Framework + Eclipse: undefined method for ReverseApplication](http://stackoverflow.com/questions/11164024/play-framework-eclipse-undefined-method-for-reverseapplication) – ndeverge Sep 02 '13 at 14:30
  • 1
    After running `play eclipse` did you refresh the project in Eclipse? (right click project name and select refresh) – frostmatthew Sep 02 '13 at 15:07
  • The framework and eclipse integration is buggy, running eclipse and reimporting the project again seems to fix these things. It's a major pita. – nylund Sep 02 '13 at 18:44
  • 1
    Try this solution: http://stackoverflow.com/questions/17806947/why-eclipse-shows-error-with-play-framework-render-method/17818347#17818347 – Marco Sep 03 '13 at 07:37
  • did my solution work for you? would be great if you could select an answer or provide the one that worked for you :) – kwikness Apr 04 '14 at 19:36

4 Answers4

16

I was having the same trouble after the recent 2.4.X release of Play and the solution of cleaning/compiling/reimporting wasn't working. The solution for me was to:

  1. Add the below keys to build.sbt
  2. Kill eclipse
  3. ./activator clean
  4. ./activator compile
  5. ./activator eclipse
  6. Re-import into eclipse

The problem is basically that the managed source directory wasn't being created, these lines fix the problem.

 EclipseKeys.projectFlavor := EclipseProjectFlavor.Java           // Java project. Don't expect Scala IDE
 EclipseKeys.createSrc := EclipseCreateSrc.ValueSet(EclipseCreateSrc.ManagedClasses, EclipseCreateSrc.ManagedResources)  // Use .class files instead of generated .scala files for views and routes 
 EclipseKeys.preTasks := Seq(compile in Compile)                  // Compile the project before generating Eclipse files, so that .class files for views and routes are present
Jason Swenski
  • 160
  • 1
  • 4
  • This *almost* works, but for a Scala project you need only the EclipseKeys.preTasks line in your build.sbt. Further information is available in the Play documentation for 2.4.x. https://www.playframework.com/documentation/2.4.x/IDE – dgabriel Jul 07 '15 at 18:43
  • 1
    Thank you! This is the correct way of doing it for Java only projects. – JavierJ Sep 24 '15 at 01:06
5
  1. run play clean-all from your project directory
  2. run play eclipse from your project directory
  3. refresh your eclipse project
kwikness
  • 1,425
  • 4
  • 21
  • 37
0

Upgrade sbteclipse to version 5.1.0 (which was released on January 12th 2017) - it fixes this bug.

mkurz
  • 2,658
  • 1
  • 23
  • 35
-2

Probably some kind of classpath issue in your Eclipse setup. Anyway, you should not rely on Eclipse to compile your Play application, simply compile it from the console and use Eclipse for source code editing only. (BTW : there are way lighter IDEs then Eclipse if you don't use it for compilation)

i.am.michiel
  • 10,281
  • 7
  • 50
  • 86
  • Even if one only wants to use Eclipse (or way lighter IDE) for pure editing joy, if Eclipse can't find some dependency, then Eclipse becomes mute and dumb. – Stephen W. Wright Mar 10 '15 at 11:58