[英]Play Framework, Java and Eclipse Luna
我是玩框架的新手。
我已經下載了最新版本的 2.5 並想用 Java 開發示例應用程序。 Java 版本是 8
我想使用 Eclipse IDE。 為此,我在 plugins.sbt 中完成了所需的設置
但是我收到諸如“無法解析索引”之類的錯誤。
如果我進行細微更改或添加另一個類,則會出現其他幾個錯誤。
我正在按照以下步驟操作:
之后,我在下面的代碼中收到錯誤“索引無法解析”:我還嘗試在 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 項目(在添加上述設置之后),請按照以下步驟操作:
target/scala-2.11/classes_managed/
存在 - 如果不存在:創建它。sbteclipse 5.1.0
修復)sbt eclipse
或activator eclipse
sbt run
/ activator run
。 訪問應用程序后,錯誤應該消失了(也許您需要右鍵單擊並點擊“刷新”或使用“F5”鍵在 Eclipse 中刷新項目)。 為什么? 因為現在路由和視圖(例如index.scala.html
)已經編譯,eclipse 現在可以引用它的類文件。 關鍵是在您運行 sbt eclipse
/ activator eclipse
, target/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.