【问题标题】:Anorm missing or invalid dependency detected while loading class file 'JavaTimeColumn.class'加载类文件“JavaTimeColumn.class”时检测到异常丢失或无效依赖项
【发布时间】:2016-03-27 02:14:27
【问题描述】:

文件 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)
  }
}

文件 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 目录)。

【问题讨论】:

  • 你用什么版本的java运行这个?
  • 标明java和anorm版本
  • java 版本 1.7.0(ubuntu /usr/lib/jvm/java-7-openjdk-amd64/jre 上的 1.7.0_65,OSX 上的 1.7.0_40 /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre)。 anorm 版本 2.5.0,如您在 build.sbt 中所见。
  • 我已经安装了 Java 1.8.0_77,现在我得到了一个更清晰的错误。它确实提到了有关缺少依赖项的任何内容,现在显示的一个错误是not found: value ~
  • ok, anorm >=2.4.0 需要 Java 8,正如其网站中所解释的那样:playframework.com/documentation/2.5.x/Anorm 库不可能声明此要求,以便编译器可以显示有用的错误信息而不是诸如误导之类的信息?

标签: scala anorm


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-12
    • 2018-09-20
    • 2020-04-06
    • 1970-01-01
    • 2017-06-12
    • 2019-02-20
    • 2011-07-22
    • 2014-10-17
    相关资源
    最近更新 更多