Reputation: 55
I am new to play framework.
I have downloaded latest version of 2.5 and want to develop sample application in Java. Java Version is 8
I want to use Eclipse IDE. for that I have done required setup in plugins.sbt
But I am getting error like "index cannot be resolved".
If I make minor changes or add another class then several other errors started.
I am following the below steps :
After that I am getting error "index cannot be resolved" in below code : I have also tried with clean the project recompile and close & open project in Eclipse. But problem remain same.
package controllers;
import play.mvc.*;
import views.html.*;
/**
* This controller contains an action to handle HTTP requests
* to the application's home page.
*/
public class HomeController extends Controller {
public Result index() {
return ok(index.render("Your new application is ready."));
}
}
Please suggest how can we configure the play framework and Eclipse.
Upvotes: 2
Views: 674
Reputation: 2826
Update: Just upgrade to sbteclipse
version 5.1.0
and everything should work out of the box.
Did you follow the documentation on how to setup sbteclipse?
Make sure you added following lines to your build.sbt
:
// Compile the project before generating Eclipse files, so that generated .scala or .class files for views and routes are present
EclipseKeys.preTasks := Seq(compile in Compile, compile in Test)
// The next two lines have to be REMOVED in case you switch to Scala IDE
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
To re-generated the eclipse project (after you added the above settings) follow this steps now:
target/scala-2.11/classes_managed/
in your projects exists - if it does not: create it.sbteclipse 5.1.0
)sbt eclipse
or activator eclipse
sbt run
/activator run
. After you accessed the app the errors should be gone (maybe you need to right click and hit "Refresh" or use the "F5" key to refresh the project in eclipse). Why? Because now the routes and views (e.g. index.scala.html
) have been compiled and eclipse can reference it's class files now.The key is that at the time you run (Fixed in sbt eclipse
/activator eclipse
the target/scala-2.11/classes_managed/
folder exists so it will be included in the eclipse classpath (the .classpath
file). Personally I put a .gitkeep
file in this folder and commit it into the git repo so I always see if the folder got deleted (But JUST this .gitkeep
file! You should never ever commit the target
folder or any of it's content into a git repo!!! This is just a personal workaround.).sbteclipse 5.1.0
)
Tip: You can also add more eclipse settings to make developing easier:
EclipseKeys.withSource := true // downloads the source of all dependencies
EclipseKeys.withJavadoc := true // downloads javadoc of dependencies
Upvotes: 1