Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sbt: selecting main class for running

Tags:

scala

sbt

I have ~6 main classes in my application, by I usually use only one of them, so I wanted to run it automatically by sbt. sbt makes it possible to define two keys in build.sbt:

// Run Key
val selectMainClass = TaskKey[Option[String]]("select-main-class", "Selects the main class to run.")
val mainClass = TaskKey[Option[String]]("main-class", "Defines the main class for packaging or running.")

so I defined them (sample project, two classes - Main1 & Main2 in the root of source dir):

mainClass := Some("Main1")

selectMainClass := Some("Main1") 

And `show main-class' from sbt prompt also seems to work:

[info] Some(Main1)

But sbt's run task still prompts me for main class.

Also, sbt-revolver fails to work with multiple classes with exception java.util.NoSuchElementException: None.get

Using sbt 0.11.2.

What am I doing wrong here?

like image 878
Rogach Avatar asked Dec 23 '11 05:12

Rogach


1 Answers

To prevent this:

sbt> ~run

Multiple main classes detected, select one to run:

[1] com.yourapp.MainClass1
[2] com.yourapp.MainClass2
[3] com.yourapp.MainClass3    

do this:

sbt> ~runMain com.yourapp.MainClass1
like image 83
radke Avatar answered Sep 23 '22 21:09

radke