Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sbt how to pass command line parameters when more than one executable

My project has a few executables. How may we run one of them with supplied command line arguments ? After attempting to include the args from sbt run they are ignored and instead the menu of available main's are listed:

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

But by selecting one of the seven options, the command line args are lost:

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
like image 744
WestCoastProjects Avatar asked Jan 11 '23 08:01

WestCoastProjects


2 Answers

You can pass straight from the command line, just by enclosing between quotes, like this:

$ sbt "runMain com.mycompany.sparkpoc.hbase.HBasePop spark://localhost:7088 localhost:2181 1000 100"
like image 140
Richard Gomes Avatar answered May 11 '23 06:05

Richard Gomes


If you want to run a specific main class, you can use runMain, and to pass command line arguments you have to specify them after the main class name.

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

For example

> runMain sample.hello.Main firstArg secondArg thirdArg
like image 22
lpiepiora Avatar answered May 11 '23 07:05

lpiepiora