我是玩框架的新手。
我已经下载了 2.5 的最新版本,想用 Java 开发示例应用程序。 Java版本为8
我想使用 Eclipse IDE。为此,我在 plugins.sbt 中完成了所需的设置
但我收到类似“无法解析索引”的错误。
如果我进行微小的更改或添加另一个类,则会出现其他几个错误。
我正在按照以下步骤操作:
- 激活新的newApp
- 在 plugin.sbt 中添加 "addSbtPlugin("com.typesafe.sbteclipse"% "sbteclipse-plugin"% "4.0.0")"
- 编译项目
- 在 Eclipse 中导入项目
之后我在下面的代码中收到错误“无法解析索引”: 我也尝试过在 Eclipse 中清理项目重新编译并关闭和打开项目。但问题仍然存在。
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."));
}
}
请建议我们如何配置 Play Framework 和 Eclipse。
最佳答案
更新:只需升级到sbteclipse
版本 5.1.0
一切都应该开箱即用。
您是否遵循了 how to setup sbteclipse 上的文档? ?
确保您在 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
要重新生成 eclipse 项目(在添加上述设置之后),请立即按照以下步骤操作:
- 在 Eclipse 中右键单击您的项目,然后选择“关闭项目”以关闭项目。
现在确保文件夹(在target/scala-2.11/classes_managed/
在您的项目中存在 - 如果不存在:创建它。sbteclipse 5.1.0
中修复)- 运行
sbt eclipse
或activator eclipse
- 现在您可以在 eclipse 中重新打开您的项目(如果需要,也可以重新导入)
- 您仍然会看到错误。继续并通过
sbt run
运行项目/activator run
.访问该应用程序后,错误应该消失了(也许您需要右键单击并点击“刷新”或使用“F5”键刷新 Eclipse 中的项目)。为什么?因为现在路由和 View (例如index.scala.html
)已经编译,eclipse 现在可以引用它的类文件。
关键是在你运行(已在 sbt eclipse
的时候/activator eclipse
target/scala-2.11/classes_managed/
文件夹存在,因此它将包含在 eclipse 类路径中(.classpath
文件)。我个人放了一个 .gitkeep
这个文件夹中的文件并将其提交到 git 仓库中,所以我总是看到该文件夹是否被删除(但只是这个 .gitkeep
文件!你永远不应该将 target
文件夹或其任何内容提交到 git 仓库中!! !这只是个人解决方法。)。sbteclipse 5.1.0
中修复)
提示: 您还可以添加更多的 eclipse 设置以简化开发:
EclipseKeys.withSource := true // downloads the source of all dependencies
EclipseKeys.withJavadoc := true // downloads javadoc of dependencies
关于java - Play Framework、Java 和 Eclipse Luna,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38288891/