Tutorial :How to inline few java lines inside an Ant script?



Question:

How to inline (here-document) few java code lines into a Ant script ? Please an example ?


Solution:1

I don't believe you can sensibly do it for actual Java code, but I've had a lot of success doing this with Groovy. The Groovy Ant task documentation is pretty good. For example:

<groovy>  xmlfiles = new File(".").listFiles().findAll{ it =~ "\.xml$" }  xmlfiles.sort().each { println it.toString() }  </groovy>  

(You can write Groovy in a much more Java-like fashion if you want to.)


Solution:2

You can add any BSF capable language to Ant, using the <script> tag, including Javascript, Groovy, JRuby etc.

The most Java-like of these is BeanShell, and is probably what you want.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »