将系统属性传递给"sbt控制台"? [英] Pass System Property to `sbt console`?
本文介绍了将系统属性传递给"sbt控制台"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从此有用的 answer 借用,我尝试将-Dfoo=bar
传递给sbt console
.
Borrowing from this helpful answer, I tried to pass -Dfoo=bar
to sbt console
.
给出一个仅具有build.sbt
的SBT项目:
Given an SBT project having only a build.sbt
:
$cat build.sbt
scalaVersion := "2.11.8"
fork := true
我尝试过:
$sbt '; set javaOptions += "-Dfoo=bar" ; console'
scala> sys.props.get("foo")
res0: Option[String] = None
但是,我给定了set ...
参数,我期望的是Some("bar")
而不是None
.
but, I had expected Some("bar")
rather than None
given the set ...
argument.
但是,使用sbt ... run
可以按预期工作:
However, using sbt ... run
worked as expected:
$cat src/main/scala/net/Main.scala
package net
object Main {
def main(args: Array[String]): Unit =
println("sys.props.get('foo'): " + sys.props.get("foo"))
}
$sbt '; set javaOptions += "-Dfoo=bar" ; run'
[info] Running net.Main
[info] sys.props.get('foo'): Some(bar)
如何将foo=bar
作为系统属性传递给console
?
How can I pass foo=bar
as a System Property to the console
?
推荐答案
run
分叉,但console
不分叉,因此简单地sbt -Dfoo=bar console
run
forks but console
doesn't, so simply sbt -Dfoo=bar console
如果需要,您可以设置它:
If need be you can set it:
- 在sbt
shell
中与eval sys.props("foo") = "bar"
- 在REPL(
console
)中与sys.props("foo") = "bar"
build.sbt
中与val setFoo = sys.props("foo") = "bar"
- in the sbt
shell
witheval sys.props("foo") = "bar"
- in the REPL (
console
) withsys.props("foo") = "bar"
- in
build.sbt
withval setFoo = sys.props("foo") = "bar"
这篇关于将系统属性传递给"sbt控制台"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文