如何runMain在Windows上从命令行执行系统属性时设置系统属性?
我希望能够运行以下命令:
sbt -Dconfig.resource=../application.conf "runMain akka.Main com.my.main.Actor"
Run Code Online (Sandbox Code Playgroud)
无论是否fork属实,我是否把它放入SBT_OPTS,或者我如何通过它我无法做到这一点.在构建中没有定义默认值时,我熟悉命令行设置的设置值吗?并使用"sbt run"设置系统属性,但都没有回答我的问题.
其他问题似乎表明您甚至无法在SBT中轻松查看Java调用参数.任何帮助表示赞赏.
Set*_*sue 43
这有效:
sbt '; set javaOptions += "-Dconfig.resource=../application.conf" ; runMain akka.Main com.my.main.Actor'
Run Code Online (Sandbox Code Playgroud)
如果这不是一个"友好"足够的语法,请将其包装在一个小的shell脚本中.
(注意这假设你已经fork设置为true来运行.如果你没有,请参阅akauppi的评论.)
Jac*_*ski 17
你可以使用envVars设置.不过,我不确定它在SBT中是多么惯用.
> help envVars
Environment variables used when forking a new JVM
Run Code Online (Sandbox Code Playgroud)
以下(非常简约)build.sbt工作正常.
fork := true
envVars := Map("msg" -> "hello")
Run Code Online (Sandbox Code Playgroud)
一旦你运行它,设置envVars为任何值与set诀窍.
> 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.
Run Code Online (Sandbox Code Playgroud)
我有一个简单的应用程序可以运行.
$ sbt run
[info] Set current project to fork-testing (in build file:/C:/dev/sandbox/fork-testing/)
[info] Running Hello
[info] hello
Run Code Online (Sandbox Code Playgroud)
在envVars命令行上更改设置后,输出将更改如下:
$ 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
Run Code Online (Sandbox Code Playgroud)
runMain与run这种情况没有什么不同.
$ 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
Run Code Online (Sandbox Code Playgroud)
如果您正在尝试设置SBT属性,例如插件设置,那么根据0.13+我的经验,上述内容将无效(AFAICT).然而,当我们尝试从CI框架传递Liquibase设置(如密码)时,以下工作确实有效.
很丑,但提供默认值,并可选择从System.properties中获取.通过这种方式,您可以覆盖默认和覆盖案例.
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")
Run Code Online (Sandbox Code Playgroud)
现在只需-Dprop=value像使用Maven或其他JVM程序一样覆盖via .注意道具出现在SBT任务之前.
sbt -Dliquibase.password="shh" -Dliquibase.username="bob" liquibase:liquibase-update
| 归档时间: |
|
| 查看次数: |
25981 次 |
| 最近记录: |