0

我正在关注ScalikeJDBCGen的这个文档,它可以从MySQL模式生成源代码。但是,在执行以下命令时,我收到ClassNotFoundException

我可以在我的 sbt 依赖项中看到 MySql。此外,我尝试通过从依赖项中删除它来运行它,怀疑相同依赖项的 2 个版本冲突(见下图)。但结果还是一样。我怎样才能解决这个问题?

在此处输入图像描述

终端

sbt "scalikejdbcGen product Product"

错误

[error] java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
[error]         at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:435)
[error]         at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
[error]         at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
[error]         at java.base/java.lang.Class.forName0(Native Method)
[error]         at java.base/java.lang.Class.forName(Class.java:340)
[error]         at scalikejdbc.mapper.ScalikejdbcPlugin$.generator(ScalikejdbcPlugin.scala:196)
[error]         at scalikejdbc.mapper.ScalikejdbcPlugin$.$anonfun$projectSettings$2(ScalikejdbcPlugin.scala:237)
[error]         at scalikejdbc.mapper.ScalikejdbcPlugin$.$anonfun$projectSettings$7(ScalikejdbcPlugin.scala:249)
[error]         at scalikejdbc.mapper.ScalikejdbcPlugin$.$anonfun$projectSettings$7$adapted(ScalikejdbcPlugin.scala:247)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:40)
[error]         at sbt.std.Transform$$anon$4.work(System.scala:67)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:269)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]         at sbt.Execute.work(Execute.scala:278)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:269)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error]         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]         at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error]         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]         at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
[error]         at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
[error]         at java.base/java.lang.Thread.run(Thread.java:832)
[error] (databaseMysql / Compile / scalikejdbcGen) java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

构建.sbt

lazy val databaseMysql =
  (project in file("database-mysql"))
    .enablePlugins(ScalikejdbcPlugin)
    .settings(
      commonSettings,
      libraryDependencies ++= Seq(
        logback,
        slf4j,
        "mysql" % "mysql-connector-java" % "5.1.12",
        "org.hsqldb" % "hsqldb" % "2.3.2",
        "org.scalikejdbc" %% "scalikejdbc"       % "3.5.0",
        "org.scalikejdbc" %% "scalikejdbc-test"   % "3.5.0"   % "test",
        "org.scalikejdbc" %% "scalikejdbc-config"  % "3.5.0",
        "com.h2database"  %  "h2"                % "1.4.200",
        "ch.qos.logback"  %  "logback-classic"   % "1.2.3",
        "org.scalikejdbc" %% "scalikejdbc-mapper-generator-core" % "3.5.0"
      )
    )
    .dependsOn(util, signrequest, test % "test->test;compile->compile")
4

1 回答 1

0

添加 JDBC 驱动程序project/plugins.sbt应该适合您!

于 2020-10-30T23:32:58.150 回答