Make42 Make42 - 29 days ago 7
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(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)


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

Answer

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

Comments