ANT:构建失败:无法创建任务或键入 testng: [英] ANT: Build Failed: failed to create task or type testng:

查看:24
本文介绍了ANT:构建失败:无法创建任务或键入 testng:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<project name="name" default="test" basedir=".">

   <!-- Define <testng> task -->

<taskdef resource="testngtasks"> 
      <classpath>
         <pathelement location="/lib/testng-6.8.5.jar"/>
      </classpath>
 </taskdef>

   <property name="testdir" location="test" />
   <property name="srcdir" location="src" />
   <property name="libdir" location="lib" />
   <property name="full-compile" value="true" />

   <path id="classpath.base"/>
   <path id="classpath.test">

   <fileset dir="${libdir}">
      <include name="**/*.jar" />
   </fileset>

   <pathelement location="${testdir}" />
   <pathelement location="${srcdir}" />

   <path refid="classpath.base" />
   </path>

   <target name="clean" >
      <delete verbose="${full-compile}">
         <fileset dir="${testdir}" includes="**/*.class" />
      </delete>
    <echo>Cleaned Successfully.</echo>
   </target>

   <target name="compile" depends="clean">
      <javac srcdir="${srcdir}" destdir="${testdir}" verbose="${full-compile}">
         <classpath refid="classpath.test"/>
      </javac>
    <echo>Java file compiled Successfully.</echo>
   </target>

   <target name="test" depends="compile">
      <testng outputdir="${testdir}" classpath="classpath.test"> 
         <xmlfileset dir="${srcdir}" includes="TestNG.xml"/> 
      </testng>
   </target>

</project>

收到以下错误:
构建失败
问题:无法创建任务或键入 testng
原因:名称未定义.
行动:检查拼写.
行动:检查是否已声明任何自定义任务/类型.
行动:检查任何/声明已经发生.

Following error is being received:
BUILD FAILED
Problem: failed to create task or type testng
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.

它有效,但现在我收到另一个错误:

It worked but now I am receiving another error:

test:    [testng] java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterExcept
    ion
       [testng]     at java.lang.Class.getDeclaredMethods0(Native Method)
       [testng]     at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
       [testng]     at java.lang.Class.getMethod0(Unknown Source)
       [testng]     at java.lang.Class.getMethod(Unknown Source)
       [testng]     at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
       [testng]     at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
       [testng] Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.Pa
    rameterException
       [testng]     at java.net.URLClassLoader$1.run(Unknown Source)
       [testng]     at java.net.URLClassLoader$1.run(Unknown Source)
       [testng]     at java.security.AccessController.doPrivileged(Native Method)
       [testng]     at java.net.URLClassLoader.findClass(Unknown Source)
       [testng]     at java.lang.ClassLoader.loadClass(Unknown Source)
       [testng]     at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       [testng]     at java.lang.ClassLoader.loadClass(Unknown Source)
       [testng]     ... 6 more
       [testng] The tests failed.

    BUILD SUCCESSFUL
    Total time: 3 seconds

以下是classpath.test,prop的输出:

Following is output of classpath.test,prop:

<path>\lib\apache-mime4j-0.6.jar;
<path>\lib\bsh-1.3.0.jar;
<path>\cglib-nodep-2.1_3.jar;
<path>\commons-codec-1.9.jar;
<path>\commons-collections-3.2.1.jar;
<path>\commons-exec-1.1.jar;
<path>\commons-io-2.4.jar;
<path>\commons-jxpath-1.3.jar;
<path>\commons-lang3-3.3.2.jar;
<path>\commons-logging-1.1.3.jar;
<path>\cssparser-0.9.14.jar;
<path>\gson-2.3.1.jar;
<path>\guava-18.0.jar;
<path>\hamcrest-core-1.3.jar;
<path>\hamcrest-library-1.3.jar;
<path>\lib\htmlunit-2.15.jar;
<path>\lib\htmlunit-core-js-2.15.jar;
<path>\lib\httpclient-4.3.6.jar;
<path>\lib\httpcore-4.3.3.jar;
<path>\lib\httpmime-4.3.6.jar;
<path>\lib\ini4j-0.5.2.jar;
<path>\lib\jcommander-1.29.jar;
<path>\lib\jetty-websocket-8.1.8.jar;
<path>\lib\jna-3.4.0.jar;
<path>\lib\jna-platform-3.4.0.jar;
<path>\lib\junit-dep-4.11.jar;
<path>\lib\nekohtml-1.9.21.jar;
<path>\lib\netty-3.5.7.Final.jar;
<path>\lib\operadriver-1.5.jar;
<path>\lib\phantomjsdriver-1.2.1.jar;
<path>\lib\protobuf-java-2.4.1.jar;
<path>\lib\sac-1.3.jar;
<path>\lib\selenium-java-2.45.0-srcs.jar;
<path>\lib\selenium-java-2.45.0.jar;
<path>\lib\serializer-2.7.1.jar;
<path>\lib\testng-6.8.5.jar;
<path>\lib\xalan-2.7.1.jar;
<path>\lib\xercesImpl-2.11.0.jar;
<path>\lib\xml-apis-1.4.01.jar;

推荐答案

我认为它找不到 jar.

I think it cannot find a jar.

试试

<taskdef resource="testngtasks" classpath="/full/path/to/testng.jar"> 
</taskdef>

或者将 testng.jar 放在 ANT_HOME/lib 中使用:

Or put testng.jar in ANT_HOME/lib and use:

<taskdef resource="testngtasks" classpath="testng.jar"> 
</taskdef>

您应该将 jar 添加到您的 classpath.test

You should add jars to your classpath.test

 <path id="classpath.test">
    <fileset dir="lib">
        <include name="**/*.jar"/>
    </fileset>  
  </path>

com/beust/jcommander/ParameterException 类在哪里定义?

您可以打印类路径以确保其中包含 jar.

You can print classpath to ensure the jar is included in it.

<pathconvert property="classpath.test.prop" refid="classpath.test"/>
<echo>Classpath is ${classpath.test.prop}</echo>

你应该在 testng 任务调用中使用 classpathref 而不是 classpath

you should use classpathref not classpath in your testng task call

<testng outputdir="${testdir}" classpathref="classpath.test"> 
         <xmlfileset dir="${srcdir}" includes="TestNG.xml"/> 
</testng>

这篇关于ANT:构建失败:无法创建任务或键入 testng:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆