27

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?

Community
  • 1
  • 1
nietaki
  • 8,758
  • 2
  • 45
  • 56

2 Answers2

31

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.

bluenote10
  • 23,414
  • 14
  • 122
  • 178
7

That's a bug in the 0.12.1 launcher: https://github.com/sbt/sbt-launcher-package/issues/34

Lukas Rytz
  • 1,894
  • 14
  • 27