[英]Ant-TestNG classpath issue: getResource can't find the file
我有一个TestNG测试,单独运行就可以很好地工作。 在它的某个地方,我得到了:
URL fileName = this.getClass().getClassLoader().getResource("config.properties");
我正在尝试使用Ant运行相同的测试:
<testng outputDir="${resultsFolder}" haltOnFailure="false">
<classpath>
<fileset dir="./src/">
<include name="**/*.properties"/>
</fileset>
-----------------------------...--------------------
</classpath>
<classfileset dir="correct path here" includes="**/*.class" />
</testng>
我可以在调试模式下看到config.properties在类路径中。 但是顶部的行找不到它,它为null。
编辑:我解决了。关键行实际上并不直接在类路径中搜索文件,而是在文件/文件夹中搜索。 因此,这解决了我的问题:
<pathelement location="src/"/>
谢谢您的帮助。
尝试以此替换您的<classpath>...</classpath>
:
<classpath>
<pathelement path="./src"/>
</classpath>
为了让JVM找到config.properties
的父目录config.properties
应该在类路径中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.