I am trying to pass command line arguments to my JAR created with sbt-assembly. Neither of these -Dconfig.file=application.conf nor -Dconfig.trace=loads

My exact command is

java -jar googleScraper-assembly-0.0.1.jar -Dconfig.trace=loads -Dconfig.resource=application.conf

This is my build.sbt

lazy val googleScraper = project.in(file("google-data-scraper"))
    version := "0.0.1",
    assemblyMergeStrategy in assembly := {
      case m if m.toLowerCase.endsWith("manifest.mf") => MergeStrategy.discard
      case m if m.toLowerCase.matches("meta-inf.*\\.sf$") => MergeStrategy.discard
      case "log4j.properties" => MergeStrategy.discard
      case m if m.toLowerCase.startsWith("meta-inf/services/") => MergeStrategy.filterDistinctLines
      case "reference.conf" => MergeStrategy.concat
      case "application.conf" => MergeStrategy.concat
      case _ => MergeStrategy.first
    libraryDependencies ++= Seq(
      "com.typesafe" % "config" % "1.3.0",
      "com.typesafe.play" % "play_2.11" % "2.3.9",
      "com.typesafe.play" % "play-ws_2.11" % "2.3.9",
      "com.ning" % "async-http-client" % "1.8.15"
    fork in run := true


So turns out that putting the argument before the -jar makes a different. This now works:

java -Dconfig.trace=loads -Dconfig.resource=blah.conf -jar googleScraper-assembly-0.0.1.jar

but it now the loading indicates that the app is trying to load the new config from within the JAR. How can I make it load it completely externally (absolute path didn't work)?

  • what is the exact command line you use to run this? When it doesn't work, how do you know (what is output?) What does the code to load the config inside the app look like (ConfigFactory.load() with no parameters, or something more complex?) – Havoc P Jul 7 '15 at 18:36
  • do you mean config.resource instead of config.file maybe? – Havoc P Jul 7 '15 at 18:40
  • Thanks! Added the exact command line. The output is either it doesn't find the resource file (when I exclude it) or it doesn't use the overrides when I have one embedded into the jar. I don't get any trace messages. My load code is just lazy ConfigFactory.load(). I have tried both config.file and config.resource but neither make a difference – Greg R Jul 7 '15 at 18:59
  • try -Dconfig.trace=loads (check readme to be sure I got that right) perhaps to see what it loads – Havoc P Jul 7 '15 at 23:34
  • 1
    oh maybe move your -D before the -jar – Havoc P Jul 8 '15 at 12:40

(extracting answer from the comments)

JVM options such as -D must come before -jar

config.file is an external file and config.resource is a resource on the classpath.

  • 1
    Awesome. java -Dconfig.file=blah.conf -jar googleScraper-assembly-0.0.1.jar worked! – Greg R Jul 9 '15 at 18:57
  • Saved a lot of time thanks to this answer! – Tomas Prado Apr 18 '16 at 14:36
  • I'm having the same problems! Even after doing exactly what was said here, I could not get this working! Here is what I'm doing: stackoverflow.com/questions/43983335/… – sparkr May 15 '17 at 18:20
  • This works fine for me. If I don't pass the config file, it assumes the existing one inside the jar. – Mário Meyrelles Aug 8 '17 at 18:41

Your Answer

