尝试使用光滑的codegen时ClassNotFoundException

时间:2016-10-20 23:23:03

标签: java scala playframework slick-3.0

我正在尝试使用自定义codegen来从mysql而不是Timestamp获取DateTime类型。我只是无法使用自定义代码生成器运行sbt任务。

类位于/ project-root / app / com / my / name

val conf = ConfigFactory.parseFile(new File("conf/application.conf")).resolve()
slick <<= slickCodeGenTask

lazy val slick = TaskKey[Seq[File]]("gen-tables")
lazy val slickCodeGenTask = (sourceManaged, dependencyClasspath in Compile, runner in Compile, streams) map { (dir, cp, r, s) =>
  val outputDir = (dir / "slick").getPath
  val url = conf.getString("slick.dbs.default.db.url")
  val jdbcDriver = conf.getString("slick.dbs.default.db.driver")
  val slickDriver = conf.getString("slick.dbs.default.driver").dropRight(1)
  val pkg = "com.my.name"
  val user = conf.getString("slick.dbs.default.db.user")
  val password = conf.getString("slick.dbs.default.db.password")
  toError(r.run(s"$pkg.CustomCodeGenerator", cp.files, Array(slickDriver, jdbcDriver, url, outputDir, pkg, user, password), s.log))
  val fname = outputDir + s"/$pkg/Tables.scala"
  Seq(file(fname))
}

当我尝试运行sbt gen-tables

时,它总是会给出相同的异常
java.lang.ClassNotFoundException: com.my.name.CustomCodeGenerator
    at java.lang.ClassLoader.findClass(ClassLoader.java:530)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sbt.classpath.ClasspathFilter.loadClass(ClassLoaders.scala:59)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at sbt.Run.getMainMethod(Run.scala:72)
    at sbt.Run.run0(Run.scala:60)
    at sbt.Run.sbt$Run$$execute$1(Run.scala:51)
    at sbt.Run$$anonfun$run$1.apply$mcV$sp(Run.scala:55)
    at sbt.Run$$anonfun$run$1.apply(Run.scala:55)
    at sbt.Run$$anonfun$run$1.apply(Run.scala:55)
    at sbt.Logger$$anon$4.apply(Logger.scala:84)
    at sbt.TrapExit$App.run(TrapExit.scala:248)
    at java.lang.Thread.run(Thread.java:745)

当我尝试一些内置的java类或默认的slick codegen类只是为了实验它创建了类

我尝试在build.sbt类中更改此任务的顺序但未解决

1 个答案:

答案 0 :(得分:0)

代替 dependencyClasspath in Compile 使用fullClasspath in Compile 参见https://www.scala-sbt.org/1.x/docs/Howto-Classpaths.html