当使用taskdef声明外部ant任务时,例如ant-contrib,建议的设置是在taskdef中使用以下内容:
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="lib/ant-contrib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>当antcontrib.properties位于相对于build.xml文件的net/sf/antcontrib中时,这是有效的。
但是当我把它放在lib/net/sf/antcontrib中并将taskdef改为
<taskdef resource="lib/net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="lib/ant-contrib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>Ant无法找到属性文件,它会给出错误
[taskdef] Could not load definitions from resource
lib/net/sf/antcontrib/antcontrib.properties. It could not be found.看起来ant单独处理lib目录,并且无法从那里加载taskdef资源。
发布于 2010-04-01 15:01:51
正如Alex所说,你不需要解开罐子的拉链。<taskdef>可以直接从jar中加载antcontrib.properties。
您得到的错误是因为您更改了资源路径,但是到压缩的jar/zip中的文件的路径仍然是相同的。任务不关注您移动的属性文件,因为您提供给<taskdef>的<classpath>告诉它只在jar中查找。
发布于 2010-01-13 08:26:19
使用antlib.xml资源:
下面是我使用的taskdef定义:
<property name="ant-contrib.jar" location="..."/>
<taskdef
resource="net/sf/antcontrib/antlib.xml"
uri="http://ant-contrib.sourceforge.net"
>
<classpath>
<pathelement location="${ant-contrib.jar}"/>
</classpath>
</taskdef>您不需要从jar文件中提取任何内容。此外,如果您不想将名称空间与antcontrib任务一起使用,则uri属性是可选的。
发布于 2010-02-09 16:07:21
为了处理任务定义的类路径,我在Ant中使用了类路径引用,这要容易得多。您可以链接包含类的目录,包含多个.jar的目录,或者(当然)单个.jar。
例如:
<!-- Properties -->
<property name="lib" value="lib/" />
<property name="classes" value="bin/" />
<!-- Classpath definition -->
<path id="runtime-classpath" >
<pathelement location="${bin}" />
<fileset dir="${lib}">
<include name="*.jar"/>
</fileset>
</path>
<!-- Taskdefs definitions -->
<taskdef name="myTask" classname="org.stackoverflow.tasks.MyTask" classpathref="runtime-classpath" />
<!-- Tasks -->
<target name="test" description="Test Action">
<myTask parameter1="value" />
</target>https://stackoverflow.com/questions/2050043
复制相似问题