0

当我通过命令提示符运行 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

蚂蚁文件:

 <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。但它仍然无法正常工作。引导我伸出援手。

4

1 回答 1

0

我知道了。实际上在文件集标签中我提到了默认路径

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

示例:C:/项目/罐子

但是在我的项目中,我没有创建文件集目录中提到的确切路径

在项目中,我保留了项目结构,如 C:/Project/Jars/lib

现在我将项目结构中的库路径更改为 C:/Project/Jars 并且它现在可以工作了。

于 2016-04-18T11:08:28.113 回答