how to set main class in SBT 0.13 project
Could you guys please explain to me how to set main class in SBT project ? I'm trying to use version 0.13.
My directory structure is very simple (unlike SBT's documentation). In the root folder I have build.sbt
with following content
name := "sbt_test"
version := "1.0"
scalaVersion := "2.10.1-local"
autoScalaLibrary := false
scalaHome := Some(file("/Program Files (x86)/scala/"))
mainClass := Some("Hi")
libraryDependencies ++= Seq(
"org.scalatest" % "scalatest_2.10" % "2.0.M5b" % "test"
)
EclipseKeys.withSource := true
And I have subfolder project
with single file Hi.scala
which contains following code
object Hi {
def main(args: Array[String]) = println("Hi!")
}
I'm able to compile it by calling sbt compile
but sbt run
returns
The system cannot find the file C:workexternalssbtbinsbtconfig.txt.
[info] Loading project definition from C:worktest_projectssbt_testproject
[info] Set current project to sbt_test (in build file:/C:/work/test_projects/sbt_test/)
java.lang.RuntimeException: No main class detected.
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) No main class detected.
[error] Total time: 0 s, completed Apr 8, 2013 6:14:41 PM
PS.
I'm shocked that after reading SBT's documentation and 15 similar questions on StackOverflow I couldn't make SBT project run. It's basic functionality which should be brain-dead simple and clear in first 10 seconds of looking at SBT's web-site.
PS2.
And I'd like to ask Typesafe employees to improve documentation of their product instead of downvoting questions of people who are investing significant time in switching to new platform.
您需要将应用程序的源代码放在src/main/scala/
, project/
用于构建定义代码。
Try to use an object and extend it from App instead of using class
object Main extends App {
println("Hello from main scala object")
}
because you need to run main method neither main class
以下是如何指定主类
mainClass in (Compile,run) := Some("my.fully.qualified.MainClassName")
上一篇: 如何配置sbt测试/ ScalaTest只显示失败?
下一篇: 如何在SBT 0.13项目中设置主类