I tried running my scala project with CLI arguments using sbt launcher version 0.12.1. It works OK when run from the scala prompt:
$ sbt
[info] (...)
> run sth
(...)
[success] Total time: 0 s, completed Nov 9, 2012 3:04:47 PM
But when I want to run it whole from shell, as per this answer for example, I'm getting an error:
$ sbt "run sth"
[info] (...)
you need to provide source file name
[success] Total time: 0 s, completed Nov 9, 2012 3:07:07 PM
[error] Not a valid command: sth (similar: set, last, shell)
[error] Expected '/'
[error] Expected ':'
[error] Not a valid key: sth (similar: test, state, watch)
[error] sth
[error] ^
And the "you need to provide source file name" info is given by my scala project to indicate that main didn't get any CLI arguments.
Is it something that worked in the previous version of sbt (in the referenced question), or am I doing something wrong?
The arguments which are passed by the user or programmer to the main() method are termed as Command-Line Arguments. main() method is the entry point of execution of a program. main() method accepts an array of strings.
An sbt shell is embedded in the sbt project and is available on your project start. You can use the sbt shell for executing sbt commands and tasks, for running, and debugging your projects.
The problem could be the way you pass arguments in your sbt
launch file to Java. In my case it is:
java -Xmx4096M -jar `dirname $0`/sbt-launch_0.12.1.jar "$@"
And I just confirmed: It works with both 0.12 and 0.12.1. For instance, for a program that just prints its arguments I get:
$ sbt "run-main SomeMain blah blah"
Outut:
[blah, blah]
By using run-main
you can also avoid the possibility that sbt somehow does not see your main function.
That's a bug in the 0.12.1 launcher: https://github.com/sbt/sbt-launcher-package/issues/34
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With