ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From goelshek <>
Subject Re: How to access value of propertyfile command line inside script
Date Mon, 06 Apr 2009 22:00:06 GMT

Thanks David. I got essentially the same information from supareno above. But
yours goes into much more details and I'm sure that would be helpful to
other people who are even newer to ant than I am.

My original question/curiosity remains: Is there no way to access the name
of the file passed in as a command line parameter of the -propertyfile flag?
I read somewhere that the properties "auto"-loaded using the -propertyfile
CL arg are in some way different than the properties loaded using the
<property file="${"/> task. That they are even more
immutable than the ones loaded using the <property/> task (if that makes any
sense whatsoever). Could that be a reason that the filename is not available
in the script?

I certainly have a solution to my problem and thank you both for that. At
this point its just more of a curiosity as to whether things are really done
in such a non-intuitive manner or am I just missing something.

David Weintraub wrote:
> My build.xml files include something like this:
> <project ...>
>     <property name="" value=""/>
>     <property file="${"/>
>     [...]
> </project>
> This way, the default name of the build properties file is
>, so if the user uses that as their build properties
> file, they don't have to put anything on the command line. If the user
> wants to use a different one, they can give that on the command line,
> and the program will use that instead of
>      $ ant""
> I also include "default" values, so if a user doesn't have a build
> properties file, they get the default values. For example:
> <project ...>
>     <property name="javac.debug.flag" value="false"/>
>     <property name="copy.verbose.flag" value="false"/>
>      [...]
>     <copy todir="${target.dir}
>          dir="${from.dir}"
>          verbose="${copy.verbose.flag}""/>
>    [...]
>     <javac
>           [...]
>           debug="${javac.debug.flag}">
> If the user wants to turn on Java debugging and verbose copying, they
> can simply do this:
>     $ant -Djavac.debug.flag=true -Dcopy.verbose.flag=true
> Otherwise, the build uses the default values I gave it before. Of
> course, the user may also use a file too to specify
> all of these flags:
>     $ ant
> Or, they can use put these values into the " file",
> and use that. Then, they don't need to use any "-D" parameters on the
> command line.
> I usually create a file in the build.xml directory called
> with the various options that the user may
> want to set (and their default values). That way, all a user has to do
> is copy to and edit the
> values they want to change.
> Remember that <properties file="..."/> will not fail if the file
> mentioned doesn't exist and that <properties> you can override
> properties values set in your build.xml file  upon the command line.
> On Mon, Apr 6, 2009 at 10:32 AM, goelshek <> wrote:
>> When I run ant as follows:
>> ant -propertyfile <property file name> <target name>
>> e.g.
>> ant -propertyfile test
>> how do I find out the the name of the properties file that the user
>> passed
>> in the command line argument. So my ant script looks like:
>> <?xml version="1.0"?>
>> <project name="ant-test" basedir=".">
>>  <target name="test">
>>  <!-- I want to print/access the name of the property file passed on
>> command line here.
>>         Would like to do something like <echo message="${propertyfile}"/>
>> -->
>>  </target>
>> </project>
>> Essentially, is there a place/property where the command line argument is
>> stored that can be accessed inside the script? I haven't been able to
>> find
>> anything so far in my search.
>> Thanks.
>> --
>> View this message in context:
>> Sent from the Ant - Users mailing list archive at
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> For additional commands, e-mail:
> -- 
> David Weintraub
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

View this message in context:
Sent from the Ant - Users mailing list archive at

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

View raw message