蚂蚁TestNG的类路径问题:的getResource找不到文件 [英] Ant-TestNG classpath issue: getResource can't find the file

查看:1035
本文介绍了蚂蚁TestNG的类路径问题:的getResource找不到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个TestNG的测试中,该工作完全正常在它自己的。某处在这我得到了:

I got a TestNG test, that works perfectly fine on it's own. Somewhere in it I got:

URL fileName = this.getClass().getClassLoader().getResource("config.properties");

我试图运行使用Ant相同的测试:

I'm trying to run the same test using 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在classpath中看到的。不过在顶部行无法找到它,它是空。

I can see in debug mode that the config.properties is in the classpath. But the line at the top can not find it, it is null.

编辑:我解决了后援临界线居然不搜索直接在类路径的文件,它搜索文件/文件夹。所以,这解决了我的问题:

I solved it.The critical line actually does not search for the file in the classpath directly, it searches IN the files/folders. So, this solved my problem:

<pathelement location="src/"/>

感谢您的帮助。

推荐答案

尝试更换你的&LT;类路径&GT; ...&LT; /类路径&GT; 与此:

<classpath>
     <pathelement path="./src"/>
</classpath>

为了让JVM找到 config.properties config.properties 的父目录应在类路径

这篇关于蚂蚁TestNG的类路径问题:的getResource找不到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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