问题
How do I do this within my build file? Say I just want to <echo/>
the name?
回答1:
There is no built-in property for the current executing target name. Some debate on this is here.
If you configure ant with log4j as a listener like this, the output will display each target start and end like below. Calling ant build
:
D:\apache-ant-1.8.0RC1\bin>ant -lib D:\log4j\log4j\1.2.13 -listener org.apache.tools.ant.listener.Log4jListener build
Buildfile: D:\apache-ant-1.8.0RC1\bin\build.xml
11:39:34 INFO Build started.
build:
11:39:34 INFO Target "build" started.
[echo] 100
11:39:34 INFO Updating property file: D:\abc.properties
[propertyfile] Updating property file: D:\abc.properties
11:39:35 INFO Target "build" finished.
BUILD SUCCESSFUL
Total time: 0 seconds
回答2:
I think this answer to pretty much the same question is more satisfactory, with a ready-to use macro to extract the value whenever necessary.
来源:https://stackoverflow.com/questions/3084946/print-access-the-name-of-the-currently-executing-ant-target