0
我正在做Scala示例Play項目https://www.playframework.com/。我已經完成了視頻中的所有步驟。然而,當我運行sbt compile
我得到這個錯誤:示例中缺少或無效的依賴項播放項目
[error] missing or invalid dependency detected while loading class file 'Logging.class'.
[error] Could not access type ScalaObject in package scala,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'Logging.class' was compiled against an incompatible version of scala.
[error] ScalaWeb/app/views/index.scala.html:5: value addPerson is not a member of controllers.ReverseApplication
[error] <form action="@routes.Application.addPerson()" method="post">
[error] ^
[error] two errors found
[error] (compile:compileIncremental) Compilation failed
出現在該文件中的錯誤:
@(message: String)
@main("Welcome to Play") {
<form action="@routes.Application.addPerson()" method="post">
<input name="name" type="text">
<button>Add Person</button>
</form>
}
我build.sbt
看起來是這樣的:
name := """ScalaWeb"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
jdbc,
cache,
ws,
specs2 % Test,
"org.sorm-framework" % "sorm" % "0.3.8"
)
resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator
scalacOptions += "-Ylog-classpath"
application.scala
看起來是這樣的:
package controllers
import models.{DB, Person}
import play.api._
import play.api.data.Form
import play.api.data.Forms._
import play.api.mvc._
class Application extends Controller {
def index = Action {
Ok(views.html.index("Your new application is ready."))
}
val personForm: Form[Person] = Form {
mapping (
"name" -> text
)(Person.apply)(Person.unapply)
}
def addPerson = Action { implicit request =>
val person = personForm.bindFromRequest.get
DB.save(person)
Redirect(routes.Application.index)
}
}
plugins.sbt
是這樣的:
// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.6")
// web plugins
addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.6")
addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")
這是什麼原因?
這似乎是用'一個問題Logging.class'。你可以添加你的構建版本嗎?也許你沒有定義你的日誌庫。 –
我沒有做任何關於日誌記錄的事情,除了添加'scalacOptions + =「-Ylog-classpath」',因爲錯誤消息提示。我沒有使用Play和SBT的經驗,但直觀地說,如果它的日誌記錄沒有配置,不應該項目工作嗎?(我不是在任何地方調用Logger) – octavian
我認爲你的問題可能在你的'routes'文件中。你在'Application.addPerson()'文件中添加了一個條目嗎? –