gpt4 book ai didi

scala - sbt 中的 mainClass 设置如何工作?

转载 作者:行者123 更新时间:2023-12-04 15:03:56 26 4
gpt4 key购买 nike

我似乎无法找到有关 mainClass 的任何细节选项适用于 sbt 的构建配置。您指定在调用 run 时要使用的类的名称。行动,但它实际上用它做什么?它是否调用类上的方法?

最佳答案

http://code.google.com/p/simple-build-tool/wiki/BuildConfiguration#Run_Options

Method mainClass is of type Option[String] and specifies an optional main class to run when the run task is invoked. The default implementation specifies no main class (None). When mainClass is not specified, the run task will determine which class to run automatically. If exactly one main class is detected, it is run. If multiple main classes are detected, the user is prompted for which one to run.



类名应引用具有 def main(args:Array[String]): Unit 的同名对象。方法。运行该方法。

所以如果你创建
package foo
object Foo { def main(args:Array[String]) { println("foo") } }

然后您可以使用 override def mainClass = Some("foo.Foo")以便运行目标运行 foo.Foo .

关于scala - sbt 中的 mainClass 设置如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5207609/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com