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

jav*_*dba 7 command-line sbt

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

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
Run Code Online (Sandbox Code Playgroud)

但是,通过选择七个选项之一,命令行参数将丢失:

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
Run Code Online (Sandbox Code Playgroud)

Ric*_*mes 6

您可以直接从命令行传递,只需用引号引起来,如下所示:

$ sbt "runMain com.mycompany.sparkpoc.hbase.HBasePop spark://localhost:7088 localhost:2181 1000 100"
Run Code Online (Sandbox Code Playgroud)


lpi*_*ora 5

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

> help runMain
Runs the main class selected by the first argument, passing the remaining arguments to the main method.
Run Code Online (Sandbox Code Playgroud)

例如

> runMain sample.hello.Main firstArg secondArg thirdArg
Run Code Online (Sandbox Code Playgroud)