2016-04-18 92 views
0

当我运行通过命令提示符Ant文件,我可以得到这样的错误:无法运行Ant文件

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 

compile: 

Testng: 
    [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(Class.java:2701)   
[testng]  at java.lang.Class.privateGetMethodRecursive(Class.java:3048)  
[testng]  at java.lang.Class.getMethod0(Class.java:3018)  
[testng]  at java.lang.Class.getMethod(Class.java:1784) 
[testng]  at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544) 
[testng]  at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.j ava:526) 
[testng]  Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.Pa rameterException 
[testng]  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)  
[testng] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)  
[testng] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 

[testng]  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)  
[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文件:

<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" /> 
    </fileset> 
    </path> 
    <!-- 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}" /> 
    </target> 

    <!-- 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}" /> 
    </target> 

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

    <!--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" 
listeners="org.uncommons.reportng.HTMLReporter"> 
     <!-- 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" /> 
    </testng> 
    </target> 
</project> 

我已经添加了jcommander jar文件和类pathelementlocation也。但它仍然不起作用。指导我伸出援手。

+0

不需要在同一个taskdef中创建多个classpath部分classpath需要多个pathelements。 https://ant.apache.org/manual/using.html#path 即使用: 不确定如何作出反应蚂蚁当有多个类路径元素无论是。 – trappski

+0

我已经删除了pathelement jcommader line.Now用这个** **单独运行程序,但仍存在相同的问题。 –

回答

0

我明白了。 其实文件集合标签我提到的默认路径

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

例如:C:/项目/罐

但在我的项目,因为它是在文件提到我没有创建确切的路径设置目录

在项目中,我不停的项目结构,如C:/项目/罐/ lib目录

现在我改变了库路径在项目结构为C:/项目/ JAR和现在的工作。