SBT 不会选择指定的 mainClass
SBT won't pick the specified mainClass
我写了这个 scala 代码
package com.abhi
import java.io.File
object Main1 {
def main(args: Array[String]) : Unit = {
println("Main1 Hello World")
}
}
object Main2 {
def main(args: Array[String]) : Unit = {
println("Main2 Hello World")
}
}
和这个 built.sbt 文件
name := "Foo"
version := "1.0"
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
"org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"
)
mainClass:= Some("com.abhi.Main1")
但是当我 运行 sbt run
它仍然说
[warn] Multiple main classes detected. Run 'show discoveredMainClasses' to see the list
Multiple main classes detected, select one to run:
[1] com.abhi.Main1
[2] com.abhi.Main2
Enter number:
为什么还问我选哪个class?要选择的主要 class 已在 build.sb
中指定
查看 How to set main class in build?
的答案
你需要这样的东西:
mainClass in (Compile, run) := Some("com.abhi.Main1")
我写了这个 scala 代码
package com.abhi
import java.io.File
object Main1 {
def main(args: Array[String]) : Unit = {
println("Main1 Hello World")
}
}
object Main2 {
def main(args: Array[String]) : Unit = {
println("Main2 Hello World")
}
}
和这个 built.sbt 文件
name := "Foo"
version := "1.0"
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
"org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"
)
mainClass:= Some("com.abhi.Main1")
但是当我 运行 sbt run
它仍然说
[warn] Multiple main classes detected. Run 'show discoveredMainClasses' to see the list
Multiple main classes detected, select one to run:
[1] com.abhi.Main1
[2] com.abhi.Main2
Enter number:
为什么还问我选哪个class?要选择的主要 class 已在 build.sb
中指定查看 How to set main class in build?
的答案你需要这样的东西:
mainClass in (Compile, run) := Some("com.abhi.Main1")