wood burning stoves 2.0*
The moose likes Ant, Maven and Other Build Tools and the fly likes Ant + Split string and assign to a property Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Ant + Split string and assign to a property" Watch "Ant + Split string and assign to a property" New topic
Author

Ant + Split string and assign to a property

Easwara Murthy
Greenhorn

Joined: Feb 12, 2009
Posts: 6
Hi,

I have a collection of strings separated by semicolon say, txt1;txt2;txt3;txt4;txt5 (which is available in a property)

I have to split this group of strings based on semicolon. While reading each string (say, first i get the string txt1), i need to assign the string to a variable (and then invoke a target). How can this be achieved using ant.

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30361
    
150

The ant-contrib library has a for loop that you can use to call a target with the split values. It assigns each one to a temporary variable when calling the new target.


[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
Donald Skidmore
Greenhorn

Joined: Aug 27, 2002
Posts: 2
<target Name="main">
<property semicolon="txt1;txt2;txt3;txt4;txt"/>
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>
<groovy>
def str=properties.semicolonstring;
def eachstr= str.split(";");
properties.str1 = eachstr[0];
properties.str2 = eachstr[1];
</groovy>
<antcall target="results"/>
</target>
<target name="results">
<echo>str1=${str1}</echo>
<echo>str2=${str2}</echo>
</target>

 
jQuery in Action, 2nd edition
 
subject: Ant + Split string and assign to a property