ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From goelshek <goels...@yahoo.com>
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="${build.properties.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="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 <goelshek@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-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
> 
> 
> 
> -- 
> David Weintraub
> qazwart@gmail.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-access-value-of-propertyfile-command-line-inside-script-tp22909968p22918340.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Mime
View raw message