Toby
Toby

Reputation: 9803

Configure "dynamic" command line arguments in sbt-native-packager

I'm trying to append command line arguments to the standard script generated by sbt-native-packager but I can't figure out how to get the behaviour I want having read the docs.

Basically, I want to add something like this to my applicaiton.ini file.

-server
-J-Xms256m
-J-Xmx512m
-Dcom.sun.management.jmxremote=true 
-Dcom.sun.management.jmxremote.port=1616 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false 
-Djava.rmi.server.hostname=$(getIpAddress) 

All good so far but you may have noticed the $(getIpAddress). I want a value assigned here from a function that'll run on the host machine.

I can add the function getIpAddress to the script template with:

bashScriptExtraDefines ++= 
   IO.readLines(sourceDirectory.value / "scripts" / "find_ip.sh")

So the content gets appended to the runner script like this:

getIpAddress() {
    echo 10.0.1.23 .  # impl snipped for brevity
}

# java_cmd is overrode in process_args when -java-home is used
declare java_cmd=$(get_java_cmd)

# if configuration files exist, prepend their contents to $@ so it can be processed by this runner
[[ -f "$script_conf_file" ]] && set -- $(loadConfigFile "$script_conf_file") "$@"

run "$@"

The set -- $(loadConfigFile "$script_conf_file") "$@" bit is prepending the java command with the content of my application.ini but it wont evaluate the function.

So, I get that the contents is prepended to the java command with -- but I don't know if I can get it to evaluate $(getIpAddress). When I execute the script, the output looks like this, showing it's not calling the function. I need the resolved value here.

$ ./my-app -v
# Executing command line:
/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/bin/java
-Xms256m
-Xmx512m
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=1616
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=$(getIpAddress)
-cp
/Users/toby/my-app.jar
my.app.Main
-serve

Is there alternative ways to achieve the same thing -- adding more "dynamic" values to the generated script? Have I got my bash commands wrong? :'(

Upvotes: 2

Views: 362

Answers (1)

dwickern
dwickern

Reputation: 3519

Arguments in the INI file won't get expanded. You could add it to the script instead:

bashScriptExtraDefines += """addJava "-Djava.rmi.server.hostname=$(getIpAddress)""""

Upvotes: 3

Related Questions