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 20:23:10 GMT

hmm...

That's an interesting solution. I'm not a big fan of specifying a property
on the command line. Especially with the -D. But this would be a way to get
things done. Thanks.

I just feel that saying:
    ant -propertyfile filename.properties test
looks a lot better/user-friendly than
    ant -Duser.propertyfile=filename.properties test

Can you, or anyone else for that matter, confirm that there is no way to
access properties file name in the ant script when it is specified using the
-propertyfile flag? In my limited experience, whenever we specify a command
line argument, there generally is a way to access that argument inside the
program to which it is passed. It just seems surprisingly non-intuitive that
the -propertyfile is not accessible inside the script itself.

I'd certainly be interested if anyone can satisfy this curiosity.



supareno wrote:
> 
> goelshek,
> 
> you can use this:
> 
> ant -D<myproperty>=<myvalue> <target>
> 
> which in your case will produce
> 
> ant -Duser.property.file=foo.properties test
> 
> <?xml version="1.0"?>
> <project name="testProps" default="test" basedir=".">
>     <property file="${user.property.file}"/>
>     <target name="test">
>        <echo>property file name: ${user.property.file}</echo>
>     </target>
> </project>
> 
> if in your properties file you define some properties
> e.g.
> prop1=foo
> prop2=bar
> 
> then, you can access them in ant with
> ${prop1}
> $[prop2}
> 
> your new target will look like this:
> [...]
>     <target name="test">
>        <echo>property file name: ${user.property.file}</echo>
>        <echo>${prop1} and ${prop2}</echo>
>     </target>
> [..]
> 
> hope this help
> 
> regards
> 
> supareno
> 
>> 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.
>>   
> 
> 
> ---------------------------------------------------------------------
> 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-tp22909968p22916503.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