我正在尝试修改光滑的codegen以使用我自己的SourceCodeGenerator
。所以我创建了自己的类SourceCodeGenerator
并将其放在app/utils
下,其中app
是我的源目录。我做了一个sbt任务并在util.MySourceCodeGenerator
中引用了这个类(build.sbt
),但我得到了可怕的
[error] (run-main-7) java.lang.ClassNotFoundException: utils.MySourceCodeGenerator
[error] java.lang.ClassNotFoundException: utils.MySourceCodeGenerator
[error] at java.lang.ClassLoader.findClass(ClassLoader.java:530)
[error] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[error] at sbt.internal.inc.classpath.ClasspathFilter.loadClass(ClassLoaders.scala:70)
[error] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[error] at java.lang.Class.forName0(Native Method)
[error] at java.lang.Class.forName(Class.java:348)
[error] at sbt.Run.getMainMethod(Run.scala:98)
[error] at sbt.Run.run0(Run.scala:86)
[error] at sbt.Run.execute$1(Run.scala:65)
运行自定义任务时:
sourceGenerators in Compile += slick.taskValue // Automatic code generation on build
lazy val slick = taskKey[Seq[File]]("Generate Tables.scala")
slick := {
val dir = (scalaSource in Compile) value
val outputDir = dir
val jdbcDriver = "org.postgresql.Driver"
val slickDriver = "slick.jdbc.PostgresProfile"
val pkg = "models"
val cp = (dependencyClasspath in Compile) value
val s = streams value
runner.value.run("utils.MySourceCodeGenerator",
cp.files,
Array(slickDriver, jdbcDriver, url, outputDir.getPath, pkg, user, password),
s.log).failed foreach (sys error _.getMessage)
val file = outputDir / pkg / "Tables.scala"
Seq(file)
}
我是否需要更改项目结构?作为参考,我在玩!框架和我基本上遵循这个https://www.playframework.com/documentation/2.6.x/Anatomy