Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set main class in SBT 0.13 project

Tags:

scala

sbt

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:\work\externals\sbt\bin\sbtconfig.txt. [info] Loading project definition from C:\work\test_projects\sbt_test\project [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 
like image 313
expert Avatar asked Apr 09 '13 01:04

expert


People also ask

What is the main function of sbt?

sbt's command engine is the means by which it processes user requests using the build state. The command engine is essentially a means of applying state transformations on the build state, to execute user requests. In sbt, commands are functions that take the current build state ( sbt.


2 Answers

You need to put your application's source in src/main/scala/, project/ is for build definition code.

like image 164
Jed Wesley-Smith Avatar answered Sep 20 '22 21:09

Jed Wesley-Smith


Try to use an object and extend it from App instead of using class

object Main extends App {   println("Hello from main scala object") } 
like image 20
Artem Avatar answered Sep 21 '22 21:09

Artem