scala SBT:启动非默认项目主类的命令行“运行”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7674615/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SBT: Start a command line 'run' of the main class of a non-default project
提问by fgysin reinstate Monica
I am starting to use sbtbuild my Scala code (and handle dependencies). As far as I know if I use
我开始使用sbt构建我的 Scala 代码(并处理依赖项)。据我所知,如果我使用
$ 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 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...)
是否可以从命令行在任何其他项目中“运行”,即不在交互式会话模式下?(我正在考虑可能看起来像$ sbt project <proj> run <args>什么的东西......)
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...
这似乎很简单,但我找不到任何描述这种行为的文档。提示将不胜感激...
回答by Moritz
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"
回答by Guillaume Massé
$ sbt foo/run arg1 arg2also work
$ sbt foo/run arg1 arg2也工作
回答by X?pplI'-I0llwlg'I -
This works: sbt "runMain com.example.Hello arg1"or sbt "run-main com.example.Hello arg1".
这有效:sbt "runMain com.example.Hello arg1"或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
请参阅此处以供参考:https: //blog.ssanj.net/posts/2016-03-02-how-to-run-a-specific-main-class-with-parameters-through-sbt.html
回答by randompast
Worked for me:
对我来说有效:
$ sbt "run someNumber"
Also this may be of some help:
这也可能有一些帮助:
def main(args: Array[String]) {
val n = args(0).toInt
}

