scala 如何将 JVM 选项传递给 SBT 以在运行应用程序或测试用例时使用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7121889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I pass JVM options to SBT to use when running the app or test cases?
提问by David Eagen
I would like to specify JVM options when running my app or the tests for the app through SBT. Specifically, I need to be able to give the JVM the -Djava.security.policy parameter so that my policy is loaded and used for the test.
我想在运行我的应用程序或通过 SBT 测试应用程序时指定 JVM 选项。具体来说,我需要能够为 JVM 提供 -Djava.security.policy 参数,以便我的策略被加载并用于测试。
How can I do this with SBT?
我怎样才能用 SBT 做到这一点?
采纳答案by VonC
With xsbt, you could run your test in a forked JVM(because of one of the reasons mentioned in "Running Project Code".
使用xsbt,您可以在分叉的 JVM 中运行您的测试(因为“运行项目代码”中提到的原因之一。
If you are using a forked jvm:
如果您使用的是分叉的 jvm:
specify the configuration to affect only the main or test run tasks:
指定仅影响主要或测试运行任务的配置:
scala javaOptions in (Test,run) += "-Xmx8G"
You should be able to specify any other options to that JVM through javaOptions.
您应该能够通过javaOptions.
The OP David Eagenreports that the following configuration didn't work at first, not because of the sbt options, but because of the path:
该OP大卫Eagen报道,下面的配置并没有工作在第一,不是因为SBT的选择,但由于路径:
lazy val escacheServer =
Project( "escache-server",
file("server"),
settings = buildSettings ++ Seq(resolvers ++=
Seq(scala_tools_snapshots, typesafe_repo),
libraryDependencies ++= escacheServerDeps,
javaOptions in run += "-Djava.security.policy=jini.policy",
fork in run := true
)
).dependsOn(escache) }
It looks like my problem was that
jini.policywasn't found in the current directory.
I set the full path and now it runs.
看起来我的问题是
jini.policy在当前目录中找不到。
我设置了完整路径,现在它运行了。

