sbt如何在多个可执行文件时传递命令行参数

时间:2014-06-26 01:24:03

标签: command-line sbt

我的项目有一些可执行文件。我们如何使用提供的命令行参数运行其中一个?在尝试包含来自 sbt run 的args后,它们将被忽略,而是列出了可用主菜单:

C:\apps\simpleakka>sbt run "com.mycompany.sparkpoc.hbase.HBasePop spark://localhost:7088 localhost:2181 1000 100"
[info] Loading project definition from C:\apps\simpleakka\project
[info] Set current project to simpleakka (in build file:/C:/apps/simpleakka/)

Multiple main classes detected, select one to run:

 [1] com.mycompany.sparkpoc.LCS
 [2] com.mycompany.sparkpoc.rdd.HBaseMR
 [3] org.apache.spark.examples.HwHBaseTest
 [4] com.mycompany.sparkpoc.rdd.HBaseMROld
 [5] com.mycompany.sparkpoc.HBaseTest
 [6] com.mycompany.sparkpoc.SocketServer
 [7] com.mycompany.sparkpoc.hbase.HBasePop

但是,通过选择七个选项中的一个,命令行args将丢失:

Enter number:

Invalid number: java.lang.NumberFormatException: For input string: ""
java.lang.RuntimeException: No main class detected.
        at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) No main class detected.
[error] Total time: 3 s, completed Jun 25, 2014 6:12:07 PM

3 个答案:

答案 0 :(得分:1)

如果要运行特定的主类,可以使用runMain,并传递命令行参数,您必须在主类名后指定它们。

> help runMain
Runs the main class selected by the first argument, passing the remaining arguments to the main method.

例如

> runMain sample.hello.Main firstArg secondArg thirdArg

答案 1 :(得分:1)

您可以直接从命令行传递,只需将引号括在引号之间,如下所示:

$ sbt "runMain com.mycompany.sparkpoc.hbase.HBasePop spark://localhost:7088 localhost:2181 1000 100"

答案 2 :(得分:0)

最接近的解决方法有点可笑,但仍然可以接受:

sbt  (go into the console, not sure the following were possible directly from command line)

现在:

run <command args>

然后出现7个主要列表。

输入选择号码(在我的情况下为7)

不知何故,sbt&#34;记得&#34;命令行选项并立即运行。