scala - 如何在运行应用程序或测试用例时将JVM选项传递给SBT以使用?

标签 scala jvm sbt

我想在运行我的应用程序或通过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/

相关文章:

java - 使用 Rhino 调用摊牌

scala - 因缺少资源而强制编译错误

scala - 为什么 vector[Option[Int]] 上的 flatMap 其映射器函数结果不是 Vector[Option[Int]] 有效?

linux - 如何检查linux为jvm分配的堆大小

java - 在 Scala 2.11.4 和 sbt 0.12.4 中加载 CharSequence 时出错

Scala 网站 : create routes

scala - 使用 IntelliJ 的 Maven Scala 项目

Java - 设置首选项后备存储目录

jvm - 对象什么时候符合 DTO 的资格?

scala - 无法在 IntelliJ + sbt-idea-plugin 中调试 Scala 应用程序