Ant-TestNG classpath issue: getResource can’t find the file

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

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

I’m trying to run the same test using Ant:

<testng outputDir="${resultsFolder}" haltOnFailure="false">
      <fileset dir="./src/">
        <include name="**/*.properties"/>
 <classfileset dir="correct path here" includes="**/*.class" />

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

EDIT: 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/"/>

Thanks for the help.


try to replace your <classpath>...</classpath> with this:

     <pathelement path="./src"/>

In order for JVM to find the the parent directory of should be in classpath.

Leave a Reply

Your email address will not be published. Required fields are marked *