i have been given skeleton sbt project work on. directory structure follows:
|-- build.sbt |-- project | |-- build.properties | |-- plugins.sbt | |-- project | `-- target |-- readme.md `-- src |-- main | `-- scala | `-- com | `-- app-name | |-- domain | |-- exception | |-- repository | `-- util `-- test `-- scala `-- vagrantfile
the instructions create app entry point should take single command line argument , run logic.
i have managed simple "hello world" sbt project working i'm new scala/sbt. place entry point , how can accept command line argument?
the root folder source files src/main/scala
.
parameters referenced using args
array within entry point object.
the entry point object under source tree extends app
. since hello world example , you're getting started, i'd drop right root of sources (src/main/scala/myapp.scala
).
something this:
object myapp extends app { println(args.length match { case 0 => "you passed in no arguments!" case 1 => s"you passed in 1 argument, ${args(0)}" case x => s"you passed in $x arguments! are: ${args.mkstring(",")}" }) }
to run app, issue sbt run
command in project root. run parameters, sbt run "arg1"
.
Comments
Post a Comment