开发者

How does the mainClass setting work in sbt?

I can't seem to find any details of how the mainClass option works in the build configuration of sbt. You specify the name of a class to use when you invo开发者_StackOverflow中文版ke the run action, but what does it actually do with it? Does it call a method on the class?


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.

The class name is expected to refer to an object of the same name that has a def main(args:Array[String]): Unit method. That method is run.

So if you create

package foo
object Foo { def main(args:Array[String]) { println("foo") } }

You can then use override def mainClass = Some("foo.Foo") so that the run target would run foo.Foo.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜