加载类文件'JavaTimeColumn.class'时检测到Anorm缺失或无效的依赖项

时间:2016-03-27 02:14:27

标签: scala anorm

文件src / main / scala / Test.scala:

import anorm.SQL
import anorm.SqlParser.{str, float}
import anorm._

object Test {
  def main(args: Array[String]) {
    val dbUrl = "jdbc:mysql://localhost:3306/test"
    Class.forName("org.gjt.mm.mysql.Driver").newInstance()
    implicit val conn: java.sql.Connection = java.sql.DriverManager.getConnection(dbUrl)

    val parser = str("name") ~ float("weight") map { case name ~ f => (name -> f) }
    val result = SQL("select name, weight from products").as(parser.single)
  }
}

file build.sbt:

scalaVersion := "2.11.7"

libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.38"

libraryDependencies += "com.typesafe.play" %% "anorm" % "2.5.0"

运行它:

$ sbt sbt-version
[info] Set current project to test (in build file:/home/david/test/)
[info] 0.13.11

$ sbt run
[info] Set current project to test (in build file:/home/david/test/)
[info] Compiling 1 Scala source to /home/david/test/target/scala-2.11/classes...
[error] missing or invalid dependency detected while loading class file 'JavaTimeColumn.class'.
[error] Could not access type ZonedDateTime in value java.time,
[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 'JavaTimeColumn.class' was compiled against an incompatible version of java.time.
[error]                                                                ^
[error] (compile:compileIncremental) Compilation failed

我从头开始尝试了一切:一个新的ubuntu虚拟机,安装了sbt并运行它(所以,没有以前的.m2,.sbt和.ivy目录)。

1 个答案:

答案 0 :(得分:1)

Play 2.4需要Java 8.所以我的猜测是Play Anorm也需要Java 8。该错误表明它正在尝试使用在Java 8中添加的java.util.time