My build.xml files include something like this:

<project ...>
    <property name="build.properties.file" value="build.properties"/>
    <property file="${build.properties.file"/>
    [...]
</project>

This way, the default name of the build properties file is
build.properties, 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 build.properties:

     $ ant -Dbuild.properties.file="my.build.properties"

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 build.properties file too to specify
all of these flags:

    $ ant -Dbuild.properties.file=debug.build.properties


Or, they can use put these values into the "build.properties 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
build.properties.template 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 build.properties.template to build.properties 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 <goels...@yahoo.com> wrote:
>
> When I run ant as follows:
>
> ant -propertyfile <property file name> <target name>
> e.g.
> ant -propertyfile myProps.properties 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: 
> http://www.nabble.com/How-to-access-value-of-propertyfile-command-line-inside-script-tp22909968p22909968.html
> Sent from the Ant - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
> For additional commands, e-mail: user-h...@ant.apache.org
>
>



-- 
David Weintraub
qazw...@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org

Reply via email to