ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Weintraub <>
Subject Re: Way to not hard-code these values?
Date Mon, 18 Oct 2010 13:04:40 GMT
There are several ways to do just this.

1. Use the -D option to define the properties you want.
2. Use the -propertyfile flag to specify a property file
3. Use the <properties file=""> field to specify which properties are
stored in a particular file.

If possible, you can define default values for the properties you
want, and then over ride them via these other methods. For example, if
you use #1 the values specified will override the default values in
your build.xml file, you have the following:

<property name="host" value=""/>
<property name="port" value="1234"/>
<host value="${host}" port="${port}"/>

And you put this on the command line:

$ ant -Dhost= -Dport=5678

host will be set to "" and not "". And, port will be set
to 5678 and not 1234.

You can put a bunch of files into a properties file in the form of:


and that too will override the properties you've set with <properties>

I prefer to do something like this:

<property name="properties.file" value="${basedir}/"/>
<property file="${properties.file}"/>

This allows someone to use a default properties file or to override
the default one on the command line via the -D option.

My preference is to use default values in the build.xml and allow the
user to override them on the command line. This meshes with my
philosophy that a developer just typing "ant" on the command line will
do more or less what they expect.

If you don't specify default values, you should use <fail> tasks to
fail the build when particular values are not set by the use via the
command line:

<fail unless="host"  message="You must set the property &quot;host&quot;"/>

David Weintraub

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message