簡體   English   中英

Play 框架、Java 和 Eclipse Luna

[英]Play Framework, Java and Eclipse Luna

我是玩框架的新手。

我已經下載了最新版本的 2.5 並想用 Java 開發示例應用程序。 Java 版本是 8

我想使用 Eclipse IDE。 為此,我在 plugins.sbt 中完成了所需的設置

但是我收到諸如“無法解析索引”之類的錯誤。

如果我進行細微更改或添加另一個類,則會出現其他幾個錯誤。

我正在按照以下步驟操作:

  1. 激活新的新應用
  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。

更新:只需升級到sbteclipse 5.1.0版,一切都應該開箱即用。


您是否按照有關 如何設置 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 eclipsetarget/scala-2.11/classes_managed/文件夾存在,因此它將包含在 eclipse 類路徑( .classpath文件)中。 就我個人而言,我將一個.gitkeep文件放在此文件夾中並將其提交到 git repo 中,因此我總是會查看該文件夾是否已被刪除(但僅此.gitkeep文件!您永遠不應該將target文件夾或其任何內容提交到 git 中回購!!!這只是個人的解決方法。)。 (已在sbteclipse 5.1.0修復)

提示:您還可以添加更多 eclipse 設置以使開發更容易:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM