Ashok kumar Ashok kumar - 10 months ago 128
Java Question

Unable to run the Ant file

When I run the ant file through command prompt, I can get an error like:

C:\Users\workspace\TestNGProject\Config>ant -buildfile reportng-build.xml Testng Buildfile: C:\Users\workspace\TestNGProject\Config\reportng-build.xml

init:[delete] Deleting directory C:\Users\workspace\TestNGProject\Config\bin-dir
[mkdir] Created dir: C:\Users\workspace\TestNGProject\Config\bin-dir
[delete] Deleting directory C:\Users\workspace\TestNGProject\Config\ht mlreport
[mkdir] Created dir: C:\Users\workspace\TestNGProject\Config\html-report


[mkdir] Created dir: C:\Users\workspace\TestNGProject\Config\htmlreport\TestNG-report
[testng] java.lang.NoClassDefFoundError:com/beust/jcommander/ParameterExcept ion
[testng] at java.lang.Class.getDeclaredMethods0(Native Method)
[testng] at java.lang.Class.privateGetDeclaredMethods(
[testng] at java.lang.Class.privateGetMethodRecursive(
[testng] at java.lang.Class.getMethod0(
[testng] at java.lang.Class.getMethod(
[testng] at sun.launcher.LauncherHelper.validateMainClass(
[testng] at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.j ava:526)
[testng] Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.Pa rameterException
[testng] at
[testng] at java.lang.ClassLoader.loadClass(
[testng] at sun.misc.Launcher$AppClassLoader.loadClass(

[testng] at java.lang.ClassLoader.loadClass(
[testng] ... 7 more [testng] Error: A JNI error has occurred, please
check your installation and try again [testng] The tests failed.

BUILD SUCCESSFUL Total time: 0 seconds

Ant file:

<project name="Testng Ant build" basedir=".">
<!-- Sets the property varaibles to point to respective directories -->
<property name="report-dir" value="${basedir}/html-report" />
<property name="testng-report-dir" value="${report-dir}/TestNG-report" />
<property name="lib-dir" value="${basedir}/lib" />
<property name="bin-dir" value="${basedir}/bin-dir" />
<property name="src-dir" value="${basedir}" />

<!-- Sets the classpath including the bin directory and all the jars under the lib folder -->
<path id="test.classpath">
<pathelement location="${bin-dir}" />
<fileset dir="${lib-dir}">
<include name="*.jar" />
<!-- Deletes and recreate the bin and report directory -->
<target name="init">
<delete dir="${bin-dir}" />
<mkdir dir="${bin-dir}" />
<delete dir="${report-dir}" />
<mkdir dir="${report-dir}" />

<!-- Compiles the source code present under the "srcdir" and
place class files under bin-dir -->
<target name="compile" depends="init">
<javac srcdir="${src-dir}" classpathref="test.classpath"
includeAntRuntime="No" destdir="${bin-dir}" />

<!-- Defines a TestNG task with name "testng" -->
<taskdef name="testng" classname="org.testng.TestNGAntTask"
<pathelement location="C:/Users/Downloads/Jars/testng- 6.9.9.jar"/>
<pathelement location="C:/Users/Downloads/Jars/jcommander-1.48.jar"/>

<!--Executes the testng tests configured in the testng.xml file-->
<target name="Testng" depends="compile">
<mkdir dir="${testng-report-dir}" />
<testng outputdir="${testng-report-dir}"
classpathref="test.classpath" useDefaultListeners="false"
<!-- Configures the testng xml file to use as test-suite -->
<xmlfileset dir="${basedir}" includes="testng.xml" />
<sysproperty key="org.uncommons.reportng.title" value="ReportNG Report" />

I have added the jcommander jar file and the class pathelementlocation also. But still it is not working. Guide me to reach out.

Answer Source

I got it. Actually in the file set tag I mentioned the default path

<fileset dir="${lib-dir}">

example: C:/Project/Jars

But in my project I didn't create the exact path as it was mentioned in file set dir

In project I kept the project structure like C:/Project/Jars/lib

Now I changed the library path in the project structure to C:/Project/Jars and it works now.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download