2

I wrote this scala code

package com.abhi

import java.io.File

object Main1 {
    def main(args: Array[String]) : Unit = {
        println("Main1 Hello World")
    }
}

object Main2 {
    def main(args: Array[String]) : Unit = {
        println("Main2 Hello World")
    }
}

and this built.sbt file

name := "Foo"

version := "1.0"

scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
    "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"   
)

mainClass:= Some("com.abhi.Main1")

But when I run sbt run it still says

[warn] Multiple main classes detected.  Run 'show discoveredMainClasses' to see the list

Multiple main classes detected, select one to run:

 [1] com.abhi.Main1
 [2] com.abhi.Main2

Enter number: 

Why is it still asking me for which class to chose? The main class to choose was already specified in the build.sb

Knows Not Much
  • 30,395
  • 60
  • 197
  • 373

1 Answers1

3

See the answer to How to set main class in build?

You'll need something like:

mainClass in (Compile, run) := Some("com.abhi.Main1")
Community
  • 1
  • 1
melps
  • 1,247
  • 8
  • 13