我需要在运行时获取可用 ant 任务的列表。基本上使用用户类路径中包含的ant库并列出所有ant任务。
最佳答案
由于 vanilla ant 通过 ant.jar 中的纯属性文件定义其任务定义,您可以使用:
<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>
列出ant core任务,输出:
[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"/>
如果有任何进一步的要求,您必须在问题中提供更多详细信息。
关于java - ANT - 如何使用 Java 从 ant 库获取可用任务列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10155993/