SBT 在 Build.scala 中指定 java 堆大小 [英] SBT Specify java heap size in Build.scala

查看:50
本文介绍了SBT 在 Build.scala 中指定 java 堆大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Build.scala 文件内容.

My Build.scala file contents.

val commonSettings = Seq(
version := "1.0.0",
organization := "com.collective",
scalaVersion := "2.11.4",
scalacOptions ++= List(
  "-encoding", "UTF-8",
  "-target:jvm-1.7",
  "-feature",
  "-unchecked",
  "-deprecation",
  "-Xlint",
  "-Xfatal-warnings"
),
resolvers ++= Seq(
  "ConJars" at "http://conjars.org/repo"
),
javaOptions in run += "-Xms256M -Xmx2G -XX:MaxPermSize=1024M -XX:+UseConcMarkSweepGC"
)

lazy val segmentFetcher = Project("segments-fetcher", file("."))
.settings(commonSettings: _*)
)

但是,当我执行

sbt run

然后查看jconsole,我在Build.scala中设置的堆大小没有被拾取.它只显示 -Xmx512M.谁能告诉我我们如何强制 sbt 从项目构建文件中选择堆空间?

and look in the jconsole, the heap size I set in the Build.scala is not picked up. It just shows -Xmx512M. Can anyone please let me know how we force sbt to pick the heap space from the project build file?

谢谢!

推荐答案

如果要改变堆大小,需要告诉 sbt fork 另一个 JVM(顺便说一下,这适用于任何 JVM 选项).您可以使用 fork 设置来执行此操作:

If you want to change the heap size, you need to tell sbt to fork another JVM (this applies to any JVM option by the way). You can use the fork setting to do so:

fork in run := true

此外,您还想确保您的选项被正确分隔(sbt 没有进行额外的解析):

Also, you want to make sure, that your options are properly separated (there is no additional parsing done by sbt):

javaOptions in run ++= Seq(
    "-Xms256M", "-Xmx2G", "-XX:MaxPermSize=1024M", "-XX:+UseConcMarkSweepGC")

或者,您可以在 sbt runner 中设置堆大小.如果使用普通sbt,可以直接修改启动脚本.如果您使用 sbt-extras,您可以使用 -J 标志将参数传递给 JVM:

Alternatively, you can set the heap size in the sbt runner. If you are using normal sbt, you can modify the launcher script directly. If you are using sbt-extras, you can pass arguments to the JVM using the -J flag:

sbt -J-Xmx2G # etc.

这篇关于SBT 在 Build.scala 中指定 java 堆大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆