我写了这个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:
为什么还要问我选择哪个班级?要选择的主要类已在build.sb
中指定答案 0 :(得分:3)
查看How to set main class in build?
的答案你需要这样的东西:
mainClass in (Compile, run) := Some("com.abhi.Main1")