How to override a Typesafe config via command line with -D

3,594 views
Skip to first unread message

l.a.derks

unread,
Aug 17, 2015, 9:37:36 AM8/17/15
to scala-user
I am trying to override a default config variable in my application.conf file.  

For example:

//application.conf
foo.bar = 50

Now I want to override foo.bar config via the command line like this:

`sbt -Dfoo.bar=100 run`

But it foo.bar keeps showing 50 instead of 100.

What am I doing wrong?

Everything works fine when I set an Environment Variable (FOO_BAR=200) and update foo.bar in application.conf like this:
foo.bar = ${?FOO_BAR} 

But the thing is I want to pass in the config via the command line. 

How can I do that?








Nick Stanchenko

unread,
Aug 17, 2015, 10:04:58 AM8/17/15
to scala-user
Hi,

I think you want sbt -J-Dfoo.bar=100 run

Nick

l.a.derks

unread,
Aug 17, 2015, 10:21:41 AM8/17/15
to scala-user
Hi Nick,

Thanks for you answer.

I just tried sbt -J-Dfoo.bar=100 run, but I keep getting the value 50 for foo.bar in my code. 

I'm using spray 1.3 by the way. Any other options?

Nick Stanchenko

unread,
Aug 17, 2015, 10:35:51 AM8/17/15
to scala-user
Hmm, not sure why that happens, but anyway -J-D is the correct way to pass system properties to sbt, much like any Java settings (e.g. -J-Xmx).
You can check that the property is there by doing ConfigFactory.systemProperties.getInt("foo.bar").

Nick

Oliver Ruebenacker

unread,
Aug 17, 2015, 10:39:48 AM8/17/15
to Nick Stanchenko, scala-user
Wouldn't you want quotation marks?

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

Nick Stanchenko

unread,
Aug 17, 2015, 10:42:21 AM8/17/15
to scala-user, nick....@gmail.com
Works for me (in zsh) :)

sbt -J-Dfoo.bar=100 console
...
[info] Starting scala interpreter...
[info] 
Welcome to Scala version 2.10.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions to have them evaluated.
Type :help for more information.

scala> com.typesafe.config.ConfigFactory.systemProperties.getInt("foo.bar")
res0: Int = 100

Oliver Ruebenacker

unread,
Aug 17, 2015, 10:44:20 AM8/17/15
to Nick Stanchenko, scala-user
Maybe that depends on the shell?

Nick Stanchenko

unread,
Aug 17, 2015, 10:45:32 AM8/17/15
to scala-user, nick....@gmail.com
Plausible, that’s why I specified mine.

Nick

Chad Retz

unread,
Aug 17, 2015, 12:19:20 PM8/17/15
to scala-user, nick....@gmail.com

Naftoli Gugenheim

unread,
Aug 18, 2015, 3:35:01 AM8/18/15
to Nick Stanchenko, scala-user

That's interesting because I'm pretty sure it works for me without the -J.

Which launcher script are you using (how did you install sbt)?


l.a.derks

unread,
Aug 18, 2015, 10:30:53 AM8/18/15
to scala-user, nick....@gmail.com
Thanks for the help.

This is the one that works for me:

sbt ";set javaOptions in run +=\"-Dfoo.bar=600\"; run”


Thanks again!

Nick Stanchenko

unread,
Aug 18, 2015, 10:36:09 AM8/18/15
to scala-user, nick....@gmail.com
@nafg: I used the debian package from http://www.scala-sbt.org/

@l.a.derks: You probably have “fork in run” set to true, right?

Nick
Reply all
Reply to author
Forward
0 new messages