Make42 Make42 - 6 months ago 35
Scala Question

How to run a sbt program in one line with arguments?

How do I run my project with a single command of sbt? I tried

sbt run src/main/resources/mydata.txt

after adding

mainClass in (Compile, run) := Some("com.mywebsite.MyExample")
mainClass in (Compile, packageBin) := Some("com.mywebsite.MyExample")

to the build.sbt, but I get

[error] (run-main-0) java.lang.ArrayIndexOutOfBoundsException: 0
java.lang.ArrayIndexOutOfBoundsException: 0
at com.mywebsite.MyExample$.main(MyExample.scala:17)
at com.mywebsite.MyExample.main(MyExample.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(

Clearly the argument did not find its way to my call of
in the main method. So what did I do wrong, how do I do it right?


sbt "run src/main/resources/mydata.txt"