Reputation: 673
How to set ${ant.project.name} value? I want to set it as: ${ant.project.name}=${basedir}
I don't want to set the project name from build.xml. My idea is - it should take the name of the folder automatically.
Is this possible?
Upvotes: 4
Views: 16616
Reputation: 107040
Why are you so intent on setting this specific property when you can set any other property your heart desires? It really doesn't make any sense either. The name of the project is completely independent of the name of the directory where you checked it out to.
However, if you insist, you can set ${ant.project.name}
by not setting it in the <project>
entity:
<project basedir="." default="package"> <!-- Notice no name! -->
<basename property="ant.project.name"
file="${basedir}"/>
<target name="package">
<echo>The name of this project is ${ant.project.name}</echo>
</target>
</project>
Upvotes: 2
Reputation: 77951
The ANT property ant.project.name is designed to return the string that appears at the top of your build file. It has special meaning and shouldn't really be changed.
The following example demonstrates how you could use an alternative property (This should work on windows as well):
<project name="demo" default="run">
<basename property="my.project.name" file="${basedir}"/>
<target name="run">
<echo message="ant.project.name=${ant.project.name}"/>
<echo message="my.project.name=${my.project.name}"/>
</target>
</project>
Has the following output
run:
[echo] ant.project.name=demo
[echo] my.project.name=myprojectdirname
Upvotes: 11
Reputation: 2702
The ant.project.name
property is set by Ant at runtime, and can't be changed. There are a handful of built-in parameters like that, documented on the Ant website. If you have a need to properties that you can change, you might be interested in ant contrib's var.
Upvotes: 1