我需要在运行时获取可用的蚂蚁任务列表。基本上使用用户类路径中包含的ant库并列出所有ant任务。

最佳答案

由于Vanilla ant通过ant.jar中的普通属性文件定义了taskdef,因此您可以使用:

<project>
 <property url="jar:file:/path/to/your/ANT_HOME/ant.jar!/org/apache/tools/ant/taskdefs/defaults.properties" prefix="antcoretasks"/>
 <echoproperties prefix="antcoretasks"/>
</project>


列出蚂蚁的核心任务,输出:

[echoproperties] #Ant properties
[echoproperties] #Sat Apr 14 21:23:41 CEST 2012
[echoproperties] antcoretasks.ant=org.apache.tools.ant.taskdefs.Ant
[echoproperties] antcoretasks.antcall=org.apache.tools.ant.taskdefs.CallTarget
[echoproperties] antcoretasks.antlr=org.apache.tools.ant.taskdefs.optional.ANTLR
[echoproperties] antcoretasks.antstructure=org.apache.tools.ant.taskdefs.AntStructure
[echoproperties] antcoretasks.antversion=org.apache.tools.ant.taskdefs.condition.AntVersion
... etc.


或将它们写入文件:

<echoproperties prefix="antcoretasks" destfile="some.file"/>


如果还有其他要求,则必须在问题中提供更多详细信息。

10-01 15:09