aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes how to edit files through ant? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "how to edit files through ant?" Watch "how to edit files through ant?" New topic
Author

how to edit files through ant?

Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31074
    
232

Is it possible to edit a file in Ant or do you need a scripting language like BSH?

What I'm really trying to do: I have an application.xml file containing an application client, an ejb and some other things. I want to create an application.xml file that does not contain the application client. So I could edit the file or create a new one. I can't find any file processing tasks in Ant or Ant contrib. Am I missing them?

Thanks,
Jeanne


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31074
    
232

I think posting this made me lucky! I just found an article that gives an example using "copy" and "filterchain."

Or I could use "loadfile" and then ant contrib's regular expression handling. That looks more promising for dealing with XML.
[ September 15, 2005: Message edited by: Jeanne Boyarsky ]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

There is one danger, however. If you put test subsititution in your copy, Ant will assume that ALL files in the copy are text files and treat them as such.

I had Ant shred a bunch of image files because I was copying them as part of a directory subtree containing config files and the DOS text conversion took all the 0x0A's in the binary images and made them 0x0A0D sequences.


Customer surveys are for companies who didn't pay proper attention to begin with.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31074
    
232

Tim,
Thanks for the words of warning.

I got it to work by doing:


In hindsight, this was rather simple to do.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to edit files through ant?