在测试期间更改SBT中的类路径

在测试期间更改SBT中的类路径,sbt,classpath,Sbt,Classpath,SBT运行测试时,如何在Java类路径中添加resourceDirectory 现在我只有sbt罐 我的需求是由于依赖项(spark cassandra connector Embedded cassandra)通过ClassLoader.getSystemResourceAsStream而不是getClass().getClassLoader()加载资源.getResource..如果要将新文件/文件夹添加到Java类pth,可以在build.sbt中添加以下行: (fullClasspath

SBT运行测试时,如何在Java类路径中添加
resourceDirectory

现在我只有sbt罐


我的需求是由于依赖项(spark cassandra connector Embedded cassandra)通过
ClassLoader.getSystemResourceAsStream
而不是
getClass().getClassLoader()加载资源.getResource
..

如果要将新文件/文件夹添加到Java类pth,可以在
build.sbt
中添加以下行:

(fullClasspath in Test) := (fullClasspath in Test).value ++ Seq(Attributed.blank((resourceDirectory in Test).value))
这将把
test:resourceDirectory
设置提供的文件夹添加到
test
配置下的类路径中

注:

fullClasspath任务提供一个类路径,包括项目的依赖项和产品。对于测试类路径,这包括项目的主资源、测试资源、编译类以及测试的所有依赖项

fullClasspath是
dependencyClasspath
exportedProducts


可以找到更多详细信息。

什么是系统类路径?对于“系统类路径”,我指的是用“java-cp…”或类路径系统属性设置的内容(使用
System.getProperty(“java.class.path”);
而不是SBT fullClasspath)。在添加您建议的内容后,我得到的是
System.out.println(s“classpath:${System.getProperty(“java.class.path”)}”)
在尝试(未成功)访问测试资源之前:classpath:/usr/local/ceral/sbt/0.13.8/libexec/sbt-launch.jar我不确定
System.getProperty(“java.class.path”)
完全满足您的需要。在SBT上尝试show
test:fullClasspath
,它将显示资源文件夹已添加。实际上,我一直在
fullClasspath
中添加了一个jar,并对其进行编译,以查看它是否已加载且一切正常。在测试中显示fullClasspath将显示配置的所有内容ured plus默认值(测试资源是其中的一部分)。这实际上是执行
getClass.getClassLoader.getResource
时查找资源的位置,而不是执行
ClassLoader.getSystemResource
时查找资源的位置(如我在问题中所述,在我使用的库中发生了什么)