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 2006

Tip: Looking for answers? Try searching our database.

Ant and XML Information Passing

Thread view: 
Jonathan Tremlett - 21 Feb 2006 09:48 GMT
Hi,

Apologies if this is not the correct place to post this - I have looked
a few places and this one seems to be the best.

I am new to Ant so think this is a relatively simple question.  My XML
files produce a name of a file.  What I need to do is to pass this back
to Ant so I can then copy the files that I need (all files in the
directories are not required as it depends on the XML content).

Any help appreciated

Jonathan Tremlett
dingbat@codesmiths.com - 21 Feb 2006 11:14 GMT
> Apologies if this is not the correct place to post this - I have looked
> a few places and this one seems to be the best.

Best I could think of too.

> I am new to Ant so think this is a relatively simple question.

You do have a copy of "Java Development with Ant", don't you?

> My XML files produce a name of a file.

Not quite sure what you mean here, so I'll interpret it as "Somewhere
in the shell that invokes Ant, I have a filename held in a shell
variable"

> What I need to do is to pass this back to Ant

Use the -D<property-name>=<property-value> command line parameter(s)
when you invoke Ant.

Make sure you're familiar with Ant properties first (which is a
minefield - read The Book Of Myrmidon).

This is all pretty easy, but processing parameters inside Ant is
unbelievably tiresome. Try to do this sort of processing outside, in
the shell script (or even embed Java helper custom tasks)

> so I can then copy the files that I need (all files in the
> directories are not required as it depends on the XML content).

BTW - I recommend that you handle file-related properties as the
"location" property type rather than the simple "value". These are
absolute paths so they can sometimes be a bit long-winded, but in
general it improves the robustness of your buildfiles.
j.tremlett@gmail.com - 22 Feb 2006 12:02 GMT
Thanks for your advice,

I was wondering if you have a variable in the XML files, is there a way
to pass this back to build.xml so Ant can then use it.  This XSL file
generates filenames and I want to pass each filename back to Ant so it
can copy each one to the relevant location.  I am currently copying
them all and therefore having many redundant files.

Any help would be appreciated

Jonathan Tremlett
dingbat@codesmiths.com - 23 Feb 2006 13:12 GMT
> I was wondering if you have a variable in the XML files, is there a way
> to pass this back to build.xml so Ant can then use it.

Not directly, by any way that I know of.

There are a few ways to pass information into Ant.

- Modify the build.xml  (brutal and generally unnecessary)

- Use a properties file, which is an easy thing to handle from Java
and an easy thing for Ant to read.

- Pass property values in on the Ant command line.

- Use Ant custom tasks (Java snippets - easy and powerful)

I don't know of any way that reads XML directly. However running XSL
over it to make a properties file would be pretty easy


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.