how to set main class in SBT 0.13 project

后端 未结 9 703
旧时难觅i
旧时难觅i 2020-12-23 18:58

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 docu

相关标签:
9条回答
  • 2020-12-23 19:25

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

    object Main extends App {
      println("Hello from main scala object")
    }
    
    0 讨论(0)
  • 2020-12-23 19:25

    Here is how to specify main class

    mainClass in (Compile,run) := Some("my.fully.qualified.MainClassName")

    0 讨论(0)
  • 2020-12-23 19:29

    If you have multiple main methods in your project you can add the following line to your build.sbt file:

    val projectMainClass = "com.saeed.ApplicationMain"
    
    mainClass in (Compile, run) := Some(projectMainClass)
    

    If you want to specify the class that will be added to the manifest when your application is packaged as a JAR file, add this line to your build.sbt file:

    mainClass in (Compile, packageBin) := Some(projectMainClass)
    

    You can also specify main class using run-main command in sbt and activator to run:

    sbt "run-main com.saeed.ApplicationMain"
    

    or

    activator "run-main com.saeed.ApplicationMain"
    
    0 讨论(0)
提交回复
热议问题