我有以下简单的项目设置
lazy val root = project.in(file(".")).aggregate(kalosrpc, kalosmodel)
lazy val kalosrpc = project.in(file("kalosrpc")).dependsOn(kalosmodel)
lazy val kalosmodel = project
.settings(
libraryDependencies ++= Seq(
dependencies.slf4j,
dependencies.slick,
dependencies.mysql
)
)
lazy val kalosgen = project
.settings(
libraryDependencies ++= Seq(
dependencies.slf4j,
dependencies.slick,
dependencies.slickCodeGen
)
)
具有以下目录结构
|__ api
|__ kalosgen
|__ src
|__ scala
|__ Main.scala
|__ kalosmodel
|__ src
|__ scala
|__ Main.scala
|__ kalosrpc
|__ src
|__ scala
|__ Main.scala
我试图只运行kalosgen
中的代码,但是当我打开sbt控制台并执行
project kalosgen
run
我知道
[error] java.lang.RuntimeException: No main class detected.
[error] at scala.sys.package$.error(package.scala:26)
[error] (Compile / bgRun) No main class detected.
这是kalosgen/src/scala/Main.scala
import slick.codegen.SourceCodeGenerator
object Main extends App {
val url = "hidden"
val user = "hidden"
val password = "hidden"
val dbDriver = "com.mysql.jdbc.Driver"
val profile = "slick.jdbc.MySQLProfile"
SourceCodeGenerator.main(
Array(
profile,
dbDriver,
url,
".",
"kalosmodel",
user,
password
)
)
}
据我所知,此设置正确无误,但无法运行,并且搜索错误消息没有帮助。我尝试使用class
代替object
,并在build.sbt
中指定主类,但没有任何效果。
答案 0 :(得分:4)
main
子目录。尝试将结构更改为
kalosgen/src/main/scala/Main.scala
代替
kalosgen/src/scala/Main.scala