Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command line arguments not working for sbt-assembly jars

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

like image 886
Greg R Avatar asked Jul 07 '15 18:07

Greg R


People also ask

What does sbt Assembly do?

The sbt-assembly plugin is an SBT plugin for building a single independent fat JAR file with all dependencies included. This is inspired by the popular Maven assembly plugin, which is used to build fat JARs in Maven.


1 Answers

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

like image 51
Havoc P Avatar answered Oct 22 '22 06:10

Havoc P