ant:无法找到jar中的资源。无法创建任务或键入类路径

时间:2014-05-22 12:27:06

标签: java xml ant

我在ant中遇到以下问题:

[taskdef] Could not load definitions from resource net/sf/antcontrib/antcontri
b.properties. It could not be found.

BUILD FAILED
build.xml:5: Problem:
failed to create task or type classpath
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.

运行以下ant build.xml:

<?xml version="1.0"?>

<project default="main" basedir=".">    
    <taskdef resource="net/sf/antcontrib/antcontrib.properties" />
    <classpath>
      <fileset dir=".">
        <include name="**/*.jar" />
      </fileset>
    </classpath>

    <target name="main">

    </target >
</project>

虽然,正在运行

<project default="main" basedir=".">    

    <path id="path.svnant">
        <pathelement location="${basedir}/ant-contrib-1.0b3.jar" />
    </path>

    <typedef resource="net/sf/antcontrib/antcontrib.properties" classpathref="path.svnant" />

    <target name="main">

    </target >
</project>

结果没有任何错误。

所以问题是为什么第一个build.xml出错了?

1 个答案:

答案 0 :(得分:0)

我想因为<classpath/>元素必须在</taskdef>元素内。

<taskdef resource="net/sf/antcontrib/antcontrib.properties" >
   <classpath>
      <fileset dir=".">
         <include name="**/*.jar" />
      </fileset>
   </classpath>
</taskdef>