开发者

SBT: Start a command line 'run' of the main class of a non-default project

开发者 https://www.devze.com 2023-04-11 08:53 出处:网络
I am starting to use sbt build my Scala code (and handle dependencies). As far as I know if I use $ sbt run <args>

I am starting to use sbt build my Scala code (and handle dependencies). As far as I know if I use

$ sbt run <args>

on the command line this will run the main class of the main project.

Is it possible to 'run' within any other project from the command开发者_StackOverflow社区 line, i.e. not in the interactive session mode? (I'm thinking about something that might look like $ sbt project <proj> run <args> or whatever...)

What I would do in interactive mode is this:

$ sbt
> project <projectname>
> run <args>

This seems to be straightforward enough, but I can not find any documentation describing this behavior. Hints would be much appreciated...


You simply have to quote each command (as in the second example on this page), so in your case it would be:

$ sbt "project foo" "run arg1 arg2"


$ sbt foo/run arg1 arg2 also work


This works: sbt "runMain com.example.Hello arg1" or sbt "run-main com.example.Hello arg1".

See here for reference: https://blog.ssanj.net/posts/2016-03-02-how-to-run-a-specific-main-class-with-parameters-through-sbt.html


Worked for me:

$ sbt "run someNumber"

Also this may be of some help:

def main(args: Array[String]) {
    val n = args(0).toInt
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号