gpt4 book ai didi

java - 找不到 taskdef 类 PackageName.ClassName

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:47:19 26 4
gpt4 key购买 nike

我正在尝试运行使用 Java + Selenium + TestNG + Ant 构建的 Selenium 测试。但是,当我运行 build.xml 时会抛出以下错误 -

BUILD FAILED
G:\Workspace\AntProject\build.xml:14: taskdef class AntPackage.AntTest cannot be found
using the classloader AntClassLoader[G:\Workspace\AntProject\libs\testng-6.8.jar]

Total time: 645 milliseconds

以下是build.xml -

<project basedir="." default="runTest" name="Ant file for TestNG">

<property name="src" location="src"/>
<property name="bin" location="bin"/>
<property name="libs" location="libs"/>

<path id="class.path">
<pathelement location="${libs}/testng-6.8.jar"/>
<pathelement location="${libs}/selenium-java-2.40.0-srcs.jar"/>
<pathelement location="${libs}/selenium-java-2.40.0.jar"/>
<pathelement location="${libs}"/>
</path>

<taskdef name="test" classname="AntPackage.AntTest">
<classpath>
<pathelement location="libs/testng-6.8.jar"/>
</classpath>
</taskdef>

<target name="runTest">
<mkdir dir="testng_output"/>
<testng outputdir="testng_output" classpathref="class.path">
<xmlfileset dir="." includes="testng.xml"/>
</testng>
</target>
</project>

下面是testng.xml -

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<test name="Test">
<classes>
<class name="AntPackage.AntTest"/>
</classes>
</test>
</suite>

AntTest 类在 AntPackage 下。

我根据 The taskdef ant task cannot be found 的回答对 build.xml 进行了更改但还是不行。

最佳答案

不要指定classname="AntPackage.AntTest"但根据文档添加 taskdef <taskdef resource="testngtasks" classpath="${libs.dir}/testng-6.8.jar" /> http://testng.org/doc/ant.html

`<taskdef />`  is needed to specify path to testng.jar but not your test classes

关于java - 找不到 taskdef 类 PackageName.ClassName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22657831/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com