Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / February 2004

Tip: Looking for answers? Try searching our database.

Recursive property resolution in ANT

Thread view: 
Dave Rudolf - 04 Feb 2004 14:53 GMT
Hi all,

So suppose that I have an ANT build file with a number of properties set in
it, and some of those properties depend on previously defined ones, like so:

   <property name="pcsRootDir" value="/pcs/pcs-HEAD">
   <property name="mncRootDir" value="/mnc_core/mnc_core-HEAD">
   <property name="fwkRootDir" value="/server_fwk/fwk">
   <property name="mncBldrSrc" value="${mncRootDir}/bldr/mnc/java/src">

... etc.

I then want to make the build file more generic, so that I can swap in new
values for those properties. I can create a *.properties file, and pass it
as a command-line param to ANT, but ANT does not recursively resolve the
values in property files.

So, is there some way to get ANT to handle these recursive definitions?
Perhaps, is there some way to include a separate XML file in the mail build
file, and this CML file contains the property definitions? I am aware that
you can map to targets in a separate XML file, but its properties are not
visible from the main build file.

Dave Rudolf
Robert Klemme - 04 Feb 2004 15:49 GMT
> Hi all,
>
[quoted text clipped - 20 lines]
>
> Dave Rudolf

You can use import:
http://ant.apache.org/manual/CoreTasks/import.html

<import file="settings-1.xml" if="settings.1"/>
<import file="settings-2.xml" if="settings.2"/>
<import file="settings-3.xml" if="settings.3"/>
<import file="settings-4.xml" if="settings.4"/>

call with "ant -Dsettings.1=t".

Regards

   robert
Ville Oikarinen - 17 Feb 2004 07:32 GMT
> I then want to make the build file more generic, so that I can swap in new
> values for those properties. I can create a *.properties file, and pass it
> as a command-line param to ANT, but ANT does not recursively resolve the
> values in property files.

If I understood correctly, you mean by "recursion" that ant will evaluate
${propertyname} strings in property values. (Strictly speaking, this would only
be recursion, if the definition referred itself (=>infinite loop), but never
mind as long as we understand each other.)

I tried this and discovered no problem.

build.xml:
<project name="testing" default="echoprops">
 <target name="echoprops">
   <property file="${propfile1}"/>
   <property file="${propfile2}"/>
   <echo message="prop1=${prop1}, derivedprop=${derivedprop}"/>
 </target>
</project>

p1.properties:
prop1=value1

p2.properties:
derivedprop=${prop1}/value2

If you now run "ant -Dpropfile1=p1.properties -Dpropfile2=p2.properties", you
will get the following output:
prop1=value1, derivedprop=value1/value2

Ville Oikarinen


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.