As others already mentioned, it's not recommended to change values of standard ant properties.
Also properties once set are immutable in ant by design and for good reasons.
Overriding properties should be used wisely and rarely.
The property ant.project.name is usually set via name attribute of project
=>
<project name="whatever">
but it's not mandatory, means
<project> ... </project>
is sufficient to make your xml a valid antscript.
In your case <echo>${ant.project.name}</echo>
would echo ${ant.project.name}
,
as property is not set, so you may create it with property task in your script :
<property name="ant.project.name" value="whatever"/>
.
But using a propertyname that is normally used for 'ant internals' seems not the best choice.
If property is set within project tag it's possible to overwrite the value via script task, using builtin javascript engine and ant api, f.e. :
<project name="foo">
<property name="bla" value="foobar"/>
<echo>1. $${ant.project.name} => ${ant.project.name}</echo>
<script language="javascript">
project.setUserProperty('ant.project.name', project.getProperty('bla'));
</script>
<echo>2. $${ant.project.name} => ${ant.project.name}</echo>
</project>
output :
[echo] 1. ${ant.project.name} => foo
[echo] 2. ${ant.project.name} => foobar
Notice : as ant.project.name is not a 'normal' property (those properties declared via property task within ant script), you have to use the method project.setUserProperty(String, String)
instead of project.setProperty(String, String)
. Userproperties are properties defined via -Dkey=value commandline argument and enjoy a special protection.
Ant also provides a bunch of builtin properties
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…