Command line arguments not working for sbt-assembly jars
Asked Answered
V

1

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

Vulturine answered 7/7, 2015 at 18:28 Comment(8)
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?)Fret
do you mean config.resource instead of config.file maybe?Fret
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 differenceVulturine
try -Dconfig.trace=loads (check readme to be sure I got that right) perhaps to see what it loadsFret
I am including that already. It doesn't get passed in. I don't see any trace messagesVulturine
oh maybe move your -D before the -jarFret
Ha, awesome. I can't believe that this worked. But now there is an error message. I updated my original question to include it.Vulturine
I'm having the same problems. Is your JAR file packaged with the conf files inside?Koloski
F
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.

Fret answered 8/7, 2015 at 22:49 Comment(3)
Awesome. java -Dconfig.file=blah.conf -jar googleScraper-assembly-0.0.1.jar worked!Vulturine
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: #43983835Koloski
This works fine for me. If I don't pass the config file, it assumes the existing one inside the jar.Precise

© 2022 - 2024 — McMap. All rights reserved.