运行时的真实SBT类路径 [英] Real SBT Classpath at Runtime
问题描述
我有一些测试用例,需要查看类路径以提取其中某些文件/目录的路径。
I have some test cases that need to look at the classpath to extract the paths of some files/directories in there. This works fine in the IDE.
问题是,在运行SBT测试时, Properties.javaClassPath
给了我 /usr/share/sbt-launcher-packaging/bin/sbt-launch.jar
。
The problem is that, when running SBT test, Properties.javaClassPath
gives me /usr/share/sbt-launcher-packaging/bin/sbt-launch.jar
.
类路径为我运行 show test:dependency-classpath
很好。有没有办法从正在运行的Scala / Java程序内部获取该信息?还是有办法将其扔到系统属性或环境变量中?
The classpath is fine when I run show test:dependency-classpath
. Is there a way to obtain that information from inside the running Scala/Java program? Or is there a way to toss it into a system property or environment variable?
推荐答案
默认情况下,测试在内部运行SBT过程,因此类路径将看起来像启动sbt时的样子(我想sbt做了一些琐事,无法动态加载测试的类)。一种执行所需操作的方法是在分支的jvm中运行测试,这样sbt将启动一个新的jvm以运行测试套件,并且应该具有预期的类路径: b
By default the tests are run inside of the SBT process, so the classpath will look like it did when you started sbt (I guess sbt does some trixery to dynamicly load the classes for the tests, not sure). One way to do what you want is to run your tests in a forked jvm, that way sbt will start a new jvm to run the test suite and that should have the expected class path:
fork in Test := true
这篇关于运行时的真实SBT类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!