我想在运行我的应用程序或通过SBT对应用程序进行测试时指定JVM选项。具体来说,我需要为JVM提供-Djava.security.policy参数,以便加载我的策略并将其用于测试。
如何使用SBT做到这一点?
最佳答案
使用xsbt,您可以在forked JVM中运行测试(因为“Running Project Code”中提到的原因之一。
如果您使用的是 fork 的jvm:
specify the configuration to affect only the main or test run tasks:
scala javaOptions in (Test,run) += "-Xmx8G"
您应该能够通过
javaOptions
为该JVM指定任何其他选项。OP David 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.policy
wasn't found in the current directory.
I set the full path and now it runs.
关于scala - 如何在运行应用程序或测试用例时将JVM选项传递给SBT以使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7121889/