【问题标题】:Play Framework, Java and Eclipse LunaPlay 框架、Java 和 Eclipse Luna
【发布时间】:2016-07-10 05:28:48
【问题描述】:

我是新手玩框架。

我已经下载了最新版本的 2.5,并想用 Java 开发示例应用程序。 Java 版本为 8

我想使用 Eclipse IDE。为此,我已经在 plugins.sbt 中完成了所需的设置

但我收到“无法解析索引”之类的错误。

如果我做了一些小改动或添加了另一个类,则会出现其他几个错误。

我遵循以下步骤:

  1. activator new newApp
  2. 在 plugin.sbt 中添加 "addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")"
  3. 编译项目
  4. 在 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."));
    }

}

请建议我们如何配置播放框架和 Eclipse。

【问题讨论】:

  • 不要露娜,去霓虹灯。
  • 索引应该解析成什么?在名为index 的方法内部,它充其量只能自行解决。
  • 我更新了我的答案:只需升级到 sbteclipse 5.1.0 版,现在一切正常。

标签: java eclipse playframework


【解决方案1】:

更新:只需升级到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 项目(添加上述设置后),请按照以下步骤操作:

  1. 在 Eclipse 中右键单击您的项目,然后选择“关闭项目”关闭项目。
  2. 现在确保您的项目中的文件夹 target/scala-2.11/classes_managed/ 存在 - 如果不存在:创建它。(在 sbteclipse 5.1.0 中修复)
  3. 运行sbt eclipseactivator eclipse
  4. 现在您可以在 Eclipse 中重新打开您的项目(或根据需要重新导入)
  5. 您仍然会看到错误。继续通过sbt run/activator run 运行项目。访问应用程序后,错误应该消失(也许您需要右键单击并点击“刷新”或使用“F5”键在 Eclipse 中刷新项目)。为什么?因为现在路由和视图(例如index.scala.html)已经编译好了,eclipse现在可以引用它的类文件了。

关键是在您运行sbt eclipse/activator eclipse 时,target/scala-2.11/classes_managed/ 文件夹存在,因此它将包含在 Eclipse 类路径(.classpath 文件)中。就我个人而言,我将.gitkeep 文件放在此文件夹中并将其提交到 git 存储库中,因此我总是查看该文件夹是否被删除(但只是这个 .gitkeep 文件!你永远不应该提交 target 文件夹或其中的任何一个将内容放入 git repo !!!这只是个人的解决方法。)。(已修复在 sbteclipse 5.1.0

提示: 您还可以添加更多 eclipse 设置以使开发更容易:

EclipseKeys.withSource := true // downloads the source of all dependencies
EclipseKeys.withJavadoc := true // downloads javadoc of dependencies

【讨论】:

  • 谢谢 mkurz。问题已解决。手动创建文件夹“classes_managed”。
  • 我更新了我的答案:只需升级到 sbteclipse 5.1.0 版,您将不再需要手动创建文件夹。
猜你喜欢
  • 2012-08-02
  • 1970-01-01
  • 2015-02-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多