通过 sbt 传递 JVM 参数 [英] Passing JVM args through sbt
问题描述
我正在尝试将第 3 方 jar 添加到我的 java 库路径.如果我使用 -Djava.library.path=a-3rd-party-lib.jar
调用 sbt,那么它适用于 run-main 的 第一次调用MyClass
在 sbt 中,但此后第 3 方代码抱怨 jar 不在 java 库路径中.我还尝试将 javaOptions += "-Djava.library.path=a-3rd-party-lib.jar"
添加到我的 build.sbt 文件中,但这并没有奏效(即使对于首轮).将此命令限定为 javaOptions in (Test,run) += "-Djava.library.path=a-3rd-party-lib.jar"
(如文档中所示)也不起作用.
I'm trying to add a 3rd party jar to my java library path. If I invoke sbt with -Djava.library.path=a-3rd-party-lib.jar
, then it works for the first invocation of run-main MyClass
inside sbt, but thereafter the 3rd party code complains that the jar is not in the java library path. I have also tried adding javaOptions += "-Djava.library.path=a-3rd-party-lib.jar"
to my build.sbt file, but this hasn't worked (even for the first run). Qualifying this command as javaOptions in (Test,run) += "-Djava.library.path=a-3rd-party-lib.jar"
(as seen in the docs) hasn't worked either.
我做错了什么,还是这是一个奇怪的错误?
Am I doing something wrong, or is this a strange bug?
仅供参考,我使用的是 sbt 0.13.0
FYI I'm using sbt 0.13.0
推荐答案
javaOptions
只有当你 fork run
并且 sbt 默认不 fork 时才会生效.有关详细信息,请参阅 分叉 文档,但对 run
和 runMain
与:
javaOptions
only takes effect if you fork run
and sbt does not fork by default. See the Forking documentation for details, but forking is enabled for run
and runMain
with:
fork in run := true
这篇关于通过 sbt 传递 JVM 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!