¿Cómo establecer las propiedades del sistema para runMain en la línea de comandos?
¿Cómo puedo establecer una propiedad del sistema para runMain
al ejecutarla desde la línea de comandos en Windows?
Me gustaría poder ejecutar el siguiente comando:
sbt -Dconfig.resource=../application.conf "runMain akka.Main com.my.main.Actor"
Independientemente de si fork
es cierto, si lo pongo en SBT_OPTS
, o cómo lo paso en no puedo lograr esto. Estoy familiarizado con Establecer el valor de configuración en la línea de comandos cuando no hay un valor predeterminado definido en la compilación? y Establecer las propiedades del sistema con"sbt run" pero ninguno responde a mi pregunta.
Otras preguntas parecen indicar que ni siquiera puede ver fácilmente los argumentos de invocación de Java en SBT. Cualquier ayuda es apreciada.
3 answers
Esto funciona:
sbt '; set javaOptions += "-Dconfig.resource=../application.conf" ; runMain akka.Main com.my.main.Actor'
Si esta sintaxis no es lo suficientemente "amigable", envuélvela en un pequeño script de shell.
(Tenga en cuenta que esto asume que tiene fork
establecido en true para ejecutar. Si no lo hace, vea el comentario de akauppi.)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-10 17:34:05
Podría usar la configuración envVars
. No estoy seguro de lo idiomático que es en SBT, sin embargo.
> help envVars
Environment variables used when forking a new JVM
Lo siguiente (muy minimalista) build.sbt
funcionó bien.
fork := true
envVars := Map("msg" -> "hello")
Una vez que se ejecuta, establecer envVars
a cualquier valor con set
hace el truco.
> help set
set [every] <setting-expression>
Applies the given setting to the current project:
1) Constructs the expression provided as an argument by compiling and loading it.
2) Appends the new setting to the current project's settings.
3) Re-evaluates the build's settings.
This command does not rebuild the build definitions, plugins, or configurations.
It does not automatically persist the setting(s) either.
To persist the setting(s), run 'session save' or 'session save-all'.
If 'every' is specified, the setting is evaluated in the current context
and the resulting value is used in every scope. This overrides the value
bound to the key everywhere.
Tengo una aplicación simple para ejecutar.
$ sbt run
[info] Set current project to fork-testing (in build file:/C:/dev/sandbox/fork-testing/)
[info] Running Hello
[info] hello
Con el ajuste envVars
cambiado en la línea de comandos, la salida cambiaría de la siguiente manera:
$ sbt 'set envVars := Map("msg" -> "Hello, Chad")' run
[info] Set current project to fork-testing (in build file:/C:/dev/sandbox/fork-testing/)
[info] Defining *:envVars
[info] The new value will be used by *:runner, compile:run::runner and 1 others.
[info] Run `last` for details.
[info] Reapplying settings...
[info] Set current project to fork-testing (in build file:/C:/dev/sandbox/fork-testing/)
[info] Running Hello
[info] Hello, Chad
runMain
no es diferente de run
en este caso.
$ sbt 'set envVars := Map("msg" -> "Hello, Chad")' 'runMain Hello'
[info] Set current project to fork-testing (in build file:/C:/dev/sandbox/fork-testing/)
[info] Defining *:envVars
[info] The new value will be used by *:runner, compile:run::runner and 1 others.
[info] Run `last` for details.
[info] Reapplying settings...
[info] Set current project to fork-testing (in build file:/C:/dev/sandbox/fork-testing/)
[info] Running Hello
[info] Hello, Chad
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-28 15:30:31
Si está tratando de establecer propiedades SBT, como la configuración del plugin, entonces lo anterior no funcionará (AFAICT) a partir de 0.13+
en mi experiencia. Sin embargo, lo siguiente funcionó, al intentar pasar la configuración de Liquibase, como la contraseña, desde nuestros marcos de CI.
En tu compilación.sbt
Feo, pero suministra valores predeterminados, y opcionalmente toma de Sistema.propiedades. De esta manera, tendrá cubiertos sus casos predeterminados y de anulación.
def sysPropOrDefault(propName:String,default:String):String = Option(System.getProperty(propName)).getOrElse(default)
liquibaseUsername := sysPropOrDefault("liquibase.username","change_me")
liquibasePassword := sysPropOrDefault("liquibase.password","chuck(\)orris")
Desde la línea de comandos
Ahora solo override vía -Dprop=value
como lo haría con Maven u otros programas JVM. Nota las prop aparecen antes de la tarea SBT.
sbt -Dliquibase.password="shh" -Dliquibase.username="bob" liquibase:liquibase-update
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-02 16:30:48