6

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"))
  .settings(commonSettings:_*)
  .settings(
    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
  )
  .dependsOn("util")
  .dependsOn("core")

Edit

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)?

Greg R
  • 1,670
  • 4
  • 26
  • 46
  • 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 07 '15 at 18:36
  • do you mean config.resource instead of config.file maybe? – Havoc P Jul 07 '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 07 '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 07 '15 at 23:34
  • I am including that already. It doesn't get passed in. I don't see any trace messages – Greg R Jul 08 '15 at 03:34
  • 1
    oh maybe move your -D before the -jar – Havoc P Jul 08 '15 at 12:40
  • Ha, awesome. I can't believe that this worked. But now there is an error message. I updated my original question to include it. – Greg R Jul 08 '15 at 20:42
  • I'm having the same problems. Is your JAR file packaged with the conf files inside? – joesan May 15 '17 at 19:07

1 Answers1

15

(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.

Havoc P
  • 8,365
  • 1
  • 31
  • 46
  • 1
    Awesome. java -Dconfig.file=blah.conf -jar googleScraper-assembly-0.0.1.jar worked! – Greg R Jul 09 '15 at 18:57
  • 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: http://stackoverflow.com/questions/43983335/scala-standalone-jar-with-a-conf-folder – joesan 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 08 '17 at 18:41