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

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

问题描述

 <,项目名称=名默认为测试BASEDIR =>   <! - 定义<&TestNG的GT;任务 - ><的taskdef资源=testngtasks>
      <&类路径GT;
         < pathelement位置=/ lib目录/ TestNG的-6.8.5.jar/>
      < /类路径>
 < /&的taskdef GT;   <属性名=TESTDIR位置=测试/>
   <属性名=SRCDIR位置=SRC/>
   <属性名=LIBDIR位置=lib目录/>
   <属性名=全编译VALUE =真/>   <路径ID =classpath.base/>
   &所述;路径ID =classpath.test>   <文件集DIR =$ {} LIBDIR>
      <包括姓名=** / *罐子。/>
   < /文件集>   < pathelement位置=$ {} TESTDIR/>
   < pathelement位置=$ {SRCDIR}/>   <路径REFID =classpath.base/>
   < /路径>   <目标名称=干净>
      <删除冗长=$ {全编译}>
         <文件集DIR =$ {} TESTDIR包括=** / *类。/>
      < /删除>
    <回声>成功清理< /回声>
   < /目标与GT;   <目标名称=编译取决于=干净>
      < javac的SRCDIR =$ {SRCDIR}DESTDIR =$ {} TESTDIR冗长=$ {全编译}>
         <类路径REFID =classpath.test/>
      < / javac的>
    <回声>的Java文件编译成功< /回声>
   < /目标与GT;   <目标名称=测试依赖=编译>
      < TestNG的outputdir =$ {} TESTDIRCLASSPATH =classpath.test>
         < xmlfileset DIR =$ {SRCDIR}包括=的testng.xml/>
      < / TestNG的>
   < /目标与GT;< /项目>

正在接收

以下错误:

构建失败

问题:无法创建任务或类型TestNG的

原因:这个名字是不确定的。

操作:检查拼写。

操作:检查所有的自定义任务/类型已经被宣布。

措施:检查所有/声明已经发生

它的工作,但现在我收到另一个错误:

 测试:TestNG的] java.lang.NoClassDefFoundError的:COM /博伊斯特/ jcommander / ParameterExcept
    离子
       [TestNG的]在java.lang.Class.getDeclaredMethods0(本机方法)
       [TestNG的]在java.lang.Class.privateGetDeclaredMethods(来源不明)
       [TestNG的]在java.lang.Class.getMethod0(来源不明)
       [TestNG的]在java.lang.Class.getMethod(来源不明)
       [TestNG的]在sun.launcher.LauncherHelper.getMainMethod(来源不明)
       [TestNG的]在sun.launcher.LauncherHelper.checkAndLoadMain(来源不明)
       [TestNG的]致:抛出java.lang.ClassNotFoundException:com.beust.jcommander.Pa
    rameterException
       [TestNG的]在java.net.URLClassLoader的$ 1.run(来源不明)
       [TestNG的]在java.net.URLClassLoader的$ 1.run(来源不明)
       [TestNG的]在java.security.AccessController.doPrivileged(本机方法)
       [TestNG的]在java.net.URLClassLoader.findClass(来源不明)
       [TestNG的]在java.lang.ClassLoader.loadClass(来源不明)
       [TestNG的]在sun.misc.Launcher $ AppClassLoader.loadClass(来源不明)
       [TestNG的]在java.lang.ClassLoader.loadClass(来源不明)
       [TestNG的] ... 6个
       [TestNG的]测试失败。    BUILD SUCCESSFUL
    总时间:3秒

以下是classpath.test的输出,道具:

 <路径> \\ lib目录\\ Apache的mime4j-0.6.jar;
<路径> \\ LIB \\ BSH-1.3.0.jar;
<路径> \\ CGLIB的nodep-2.1_3.jar;
<路径> \\ commons- codeC-1.9.jar;
<路径> \\ commons-collections提供-3.2.1.jar;
<路径> \\公地的exec-1.1.jar;
<路径> \\公地IO-2.4.jar;
<路径> \\公地的JXPath-1.3.jar;
<路径> \\公地lang3-3.3.2.jar;
<路径> \\的commons-logging-1.1.3.jar;
<路径> \\ cssparser-0.9.14.jar;
<路径> \\ GSON-2.3.1.jar;
<路径> \\番石榴18.0.jar;
<路径> \\ hamcrest核-1.3.jar;
<路径> \\ hamcrest库-1.3.jar;
<路径> \\ LIB \\的HtmlUnit,2.15.jar;
<路径> \\ LIB \\的HtmlUnit核心JS-2.15.jar;
<路径> \\ LIB \\ HttpClient的-4.3.6.jar;
<路径> \\ LIB \\的HttpCore-4.3.3.jar;
<路径> \\ LIB \\ httpmime-4.3.6.jar;
<路径> \\ LIB \\ ini4j-0.5.2.jar;
<路径> \\ LIB \\ jcommander,1.29.jar;
<路径> \\ LIB \\码头-的WebSocket-8.1.8.jar;
<路径> \\ LIB \\ JNA-3.4.0.jar;
<路径> \\ LIB \\ JNA平台-3.4.0.jar;
<路径> \\ LIB \\的junit-DEP-4.11.jar;
<路径> \\ LIB \\ nekohtml-1.9.21.jar;
<路径> \\ LIB \\网状,3.5.7.Final.jar;
<路径> \\ LIB \\ operadriver-1.5.jar;
<路径> \\ LIB \\ phantomjsdriver-1.2.1.jar;
<路径> \\ LIB \\的protobuf-java的2.4.1.jar;
<路径> \\ LIB \\ SAC-1.3.jar;
<路径> \\ LIB \\硒-java的2.45.0-srcs.jar;
<路径> \\ LIB \\硒Java的2.45.0.jar;
<路径> \\ LIB \\串行 - 2.7.1.jar;
<路径> \\ LIB \\ TestNG的-6.8.5.jar;
<路径> \\ LIB \\ xalan的-2.7.1.jar;
<路径> \\ LIB \\ xercesImpl,2.11.0.jar;
<路径> \\ LIB \\ XML的API-1.4.01.jar;


解决方案

我觉得不能找到一个罐子。

尝试

 <的taskdef资源=testngtasksCLASSPATH =/全/路径/要/ testng.jar>
< /&的taskdef GT;

或在ANT_HOME把testng.jar / lib和用途:

 <的taskdef资源=testngtasksCLASSPATH =testng.jar>
< /&的taskdef GT;

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

 <路径ID =classpath.test>
    <文件集DIR =lib目录>
        <包括姓名=** / *罐子。/>
    < /文件集>
  < /路径>

凡类 COM /博伊斯特/ jcommander / ParameterException 定义?

您可以打印类路径,以确保瓶子被包含在里面。

 < pathconvert财产=classpath.test.propREFID =classpath.test/>
<回声>类路径是$ {classpath.test.prop}< /回声>

你应该使用 classpathref 不是的classpath 在TestNG的任务调用

 < TestNG的outputdir =$ {} TESTDIRclasspathref =classpath.test>
         < xmlfileset DIR =$ {SRCDIR}包括=的testng.xml/>
< / 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>

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

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;

解决方案

I think it cannot find a jar.

Try

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

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

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

You should add jars to your classpath.test

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

Where the class com/beust/jcommander/ParameterException is defined?

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>

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天全站免登陆