Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Maven依赖项在Ant中测试taskdef定义_Ant_Maven_Dependencies_Testng_Taskdef - Fatal编程技术网

使用Maven依赖项在Ant中测试taskdef定义

使用Maven依赖项在Ant中测试taskdef定义,ant,maven,dependencies,testng,taskdef,Ant,Maven,Dependencies,Testng,Taskdef,我正在尝试使用Ant和Maven来构建一个项目。我将testNG用于测试单元。如本文所述,我对taskdef的定义如下: <taskdef resource="testngtasks" classpath="testng.jar"/> 蚂蚁 在Maven中,我添加了如下内容: Maven正在从Maven存储库获取文件,我已经检查了/.m2下的位置。既然我从maven获得了testNG,我应该在ant中更改taskdef以在maven存储库中使用这个新的。我不知道该怎么做。我尝试了

我正在尝试使用Ant和Maven来构建一个项目。我将testNG用于测试单元。如本文所述,我对taskdef的定义如下:

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

在Maven中,我添加了如下内容:

Maven正在从Maven存储库获取文件,我已经检查了/.m2下的位置。既然我从maven获得了testNG,我应该在ant中更改taskdef以在maven存储库中使用这个新的。我不知道该怎么做。我尝试了以下方法:

<taskdef resource ="testngtasks" classname="org.testng" /> 

但是没有成功,第二个抱怨我不应该使用classpathref,第一个说我应该指定类。第三个是工作的一种,但不完全。它正在运行,我猜它通过了taskdef步骤,但它没有执行测试。第三个是蚂蚁的一部分:

<taskdef  resource="testngtasks"  />

<target name="test" depends="compile">
<echo message="running tests" />
Ant输出的一部分:请注意,在执行echo时,它以某种方式通过了taskdef步骤

compile:
    [javac] /home/shahin/Files/Development/Ant/ServiceEJBSample3/build-testNG.xml:31: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds

test:
     [echo] running tests

BUILD FAILED
/home/shahin/Files/Development/Ant/ServiceEJBSample3/build-testNG.xml:84: 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 <presetdef>/<macrodef> declarations have taken place.

我不知道如何使用Maven存储库中的testNG库在Ant中定义taskdef和testngtasks。如果您有任何见解,我们将不胜感激

请尝试在taskdef的类路径中放置pathelement属性,如:

<taskdef resource="testngtasks">
     <classpath>
          <pathelement path="[path to]/testng.jar"/>
     </classpath>
</taskdef>

首先,对pathelement的路径进行硬编码,以确保它适合您。

我使用以下taskdef使其工作:

<taskdef resource="testngtasks" classpath="./lib/testng-6.2.jar"/>
当Maven检索jar时,它将不会被命名为testng.jar。因此,您需要将其重命名为适当的jar,并更新jar的路径

compile:
    [javac] /home/shahin/Files/Development/Ant/ServiceEJBSample3/build-testNG.xml:31: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds

test:
     [echo] running tests

BUILD FAILED
/home/shahin/Files/Development/Ant/ServiceEJBSample3/build-testNG.xml:84: 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 <presetdef>/<macrodef> declarations have taken place.
<taskdef resource="testngtasks">
     <classpath>
          <pathelement path="[path to]/testng.jar"/>
     </classpath>
</taskdef>
<taskdef resource="testngtasks" classpath="./lib/testng-6.2.jar"/>