0

Below is my Build.xml file. I am trying to execute my TestNG.xml through Build.xml but I am getting the below error every time:

[testng] Cannot find class in classpath:

The below file is working fine till the compile target. I guess there are some issues with the code written in exec target.

I have tried resolving the issue by a number of methods that I found on stackoverflow such as: Cleaning the project, updating the TestNG library but it didn't work out.

Can anybody help me on this?

<property name="lib" value="./lib" />

<property name="bin" value="./bin" />

<path id="Sample Ant build.classpath">
    <pathelement location="${output}" />
    <fileset dir="${lib}">
        <include name="**/*.jar" />
    </fileset>
</path>

<target name="init">
    <delete dir="${bin}">
    </delete>
    <mkdir dir="${bin}" />
</target>

<target name="compile" depends="init">
    <javac srcdir="${src}" 
         destdir="${bin}"
        includeantruntime="false"   
         debug="true">
        <classpath refid="Sample Ant build.classpath"/>
    </javac>
</target>

<!-- Runs the file and generates Reportng report for TestNG-->
<taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="Sample Ant build.classpath" />

<target name="exec" depends="compile">
    <mkdir dir="${testng_report_dir}" />
    <testng outputdir="${testng_report_dir}" classpathref="Sample Ant build.classpath" useDefaultListeners="true">
        <xmlfileset dir="${basedir}" includes="Testng.xml" />
    </testng>

</target>
2
  • if you are using pom.xml for dependency management, then change the scope to compile in testng dependency. Apr 24 '17 at 8:53
  • No. I am using build.xml. Thank you for your response. I just resolved this issue. Thank you. Apr 24 '17 at 14:35
1

I just resolved this issue. The problem was in the classpath that I had set in the build.xml:

<path id="classpath">
    <pathelement location="${bin}" />
    <fileset dir="${lib}">
        <include name="**/*.jar" />
    </fileset>
</path>  
1
  • bin directory contains the class file which gets generate upon compilation of your .java file Apr 24 '17 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.