无法找到 taskdef class org.testng.TestNGAntTask
taskdef class org.testng.TestNGAntTask cannot be found
我正在尝试让 ant 编译并继续获取:
taskdef class org.testng.TestNGAntTask cannot be found
我看到的大多数示例在类路径中都有:${libs.dir}/testng-6.8.jar
我也试过:
<taskdef name="testng" classpath="${test.classpath}"
classname="org.testng.TestNGAntTask" />
我的部分 build.xml
<property environment="env"/>
<property name="ws.home" value="${basedir}"/>
<property name="ws.jars" value="C:\jars"/>
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="ng.result" value="test-output"/>
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes="*.jar"/>
</path>
<pathconvert pathsep=":" property="test.classpath" refid="classpath_jars"/>
</target>
我应该使用什么路径,我怎么知道我有什么版本的testng.jar
我的eclipse环境截图
如果我用 -v
编译,我得到:
[echo] classpath------: C:\jars\testng.jar
我将 testng.jar
复制到此目录,但仍然没有成功。
创建任务时尝试使用路径引用,而不是 属性。例如:
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes="*.jar"/>
</path>
<taskdef name="testng" classpathref="classpath_jars" classname="org.testng.TestNGAntTask" />
未来考虑
What path should I use and how do I know what version of testng.jar I
have
您是否考虑过将 Maven 风格的依赖管理添加到您的构建中?
这将使您更加确定您的构建过程正在根据您的要求使用哪些罐子。就目前而言,您依靠手动配置将正确的 jar 放在预期的目录中。
依赖管理是 Apache ivy plugin. It provides additional tasks that enable you to manage classpaths via jars automatically downloaded and cached from the Central Maven repository 提供的功能。
例如:
<ivy:cachepath pathid="build.path">
<dependency org="org.testng" name="testng" rev="6.11" conf="default"/>
</ivy:cachepath>
<taskdef name="testng" classpathref="build.path" classname="org.testng.TestNGAntTask" />
以下更完整的示例演示了如何配置 ANT 以自动设置 ivy 插件,使您的构建可移植到所有机器上。您只需要 Java 并安装 ANT。
build.xml
<project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">
<!--
================
Build properties
================
-->
<available classname="org.apache.ivy.Main" property="ivy.installed"/>
<!--
==========
Build main
==========
-->
<target name="build" depends="install-ivy">
<ivy:cachepath pathid="build.path">
<dependency org="org.testng" name="testng" rev="6.11" conf="default"/>
</ivy:cachepath>
<taskdef name="testng" classpathref="build.path" classname="org.testng.TestNGAntTask" />
</target>
<!--
===========
Build setup
===========
-->
<target name="install-ivy" description="Install ivy" unless="ivy.installed">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar"/>
<fail message="Ivy has been installed. Run the build again"/>
</target>
</project>
我正在尝试让 ant 编译并继续获取:
taskdef class org.testng.TestNGAntTask cannot be found
我看到的大多数示例在类路径中都有:${libs.dir}/testng-6.8.jar
我也试过:
<taskdef name="testng" classpath="${test.classpath}"
classname="org.testng.TestNGAntTask" />
我的部分 build.xml
<property environment="env"/>
<property name="ws.home" value="${basedir}"/>
<property name="ws.jars" value="C:\jars"/>
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="ng.result" value="test-output"/>
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes="*.jar"/>
</path>
<pathconvert pathsep=":" property="test.classpath" refid="classpath_jars"/>
</target>
我应该使用什么路径,我怎么知道我有什么版本的testng.jar
如果我用 -v
编译,我得到:
[echo] classpath------: C:\jars\testng.jar
我将 testng.jar
复制到此目录,但仍然没有成功。
创建任务时尝试使用路径引用,而不是 属性。例如:
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes="*.jar"/>
</path>
<taskdef name="testng" classpathref="classpath_jars" classname="org.testng.TestNGAntTask" />
未来考虑
What path should I use and how do I know what version of testng.jar I have
您是否考虑过将 Maven 风格的依赖管理添加到您的构建中? 这将使您更加确定您的构建过程正在根据您的要求使用哪些罐子。就目前而言,您依靠手动配置将正确的 jar 放在预期的目录中。
依赖管理是 Apache ivy plugin. It provides additional tasks that enable you to manage classpaths via jars automatically downloaded and cached from the Central Maven repository 提供的功能。
例如:
<ivy:cachepath pathid="build.path">
<dependency org="org.testng" name="testng" rev="6.11" conf="default"/>
</ivy:cachepath>
<taskdef name="testng" classpathref="build.path" classname="org.testng.TestNGAntTask" />
以下更完整的示例演示了如何配置 ANT 以自动设置 ivy 插件,使您的构建可移植到所有机器上。您只需要 Java 并安装 ANT。
build.xml
<project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">
<!--
================
Build properties
================
-->
<available classname="org.apache.ivy.Main" property="ivy.installed"/>
<!--
==========
Build main
==========
-->
<target name="build" depends="install-ivy">
<ivy:cachepath pathid="build.path">
<dependency org="org.testng" name="testng" rev="6.11" conf="default"/>
</ivy:cachepath>
<taskdef name="testng" classpathref="build.path" classname="org.testng.TestNGAntTask" />
</target>
<!--
===========
Build setup
===========
-->
<target name="install-ivy" description="Install ivy" unless="ivy.installed">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar"/>
<fail message="Ivy has been installed. Run the build again"/>
</target>
</project>