Skip to content

Groovy Ant Script- First Blush

Most every Java developer these days has written an ant script. Some of us have had the great fortune of writing a lot of ant scripts. And as cool as it is, it gets extremely tedious writing XML.

Enter Groovy‘s AntBuilder. I’ve been writing some groovy scripts lately and have wanted to take a look at AntBuilder for a while now. I have a feeling my next few posts will be on this topic.

Here’s a first example:

JAR_FILE = 'updater.jar'
SRC_DIR = 'src'
DEST_DIR = 'bin'
LIB_DIR = '../Base'
CLASSPATH = 'updaterClasspath'
RUNTIMEPATH = 'updaterRuntime'

ant = new AntBuilder()

cPath = ant.path(id:CLASSPATH) {
	pathelement(location:LIB_DIR)
	fileset(dir:LIB_DIR + "/antlr", includes:"antlr-2.7.6.jar")
	pathelement(location:LIB_DIR)
	fileset(dir:LIB_DIR + "/oracle", includes:"ojdbc14.jar")
	pathelement(location:LIB_DIR)
	fileset(dir:LIB_DIR + "/jakarta-commons", includes:"*.jar")
	pathelement(location:LIB_DIR)
	fileset(dir:LIB_DIR + "/cglib", includes:"cglib-nodep-2.1_3.jar")
	pathelement(location:LIB_DIR)
	fileset(dir:LIB_DIR + "/dom4j", includes:"dom4j-1.6.1.jar")
	pathelement(location:LIB_DIR)
	fileset(dir:LIB_DIR + "/hibernate", includes:"*.jar")
	pathelement(location:LIB_DIR)
	fileset(dir:LIB_DIR + "/log4j", includes:"log4j-1.2.14.jar")
	pathelement(location:LIB_DIR)
	fileset(dir:LIB_DIR + "/spring", includes:"spring.jar")
}

// Uncomment this below to print the classpath
//for (f in cPath) {
//    println("Found file ${f}")
//}

ant.javac(srcDir:SRC_DIR,
		destDir:DEST_DIR,
		classpathref:CLASSPATH)

ant.jar(destFile:JAR_FILE,
		baseDir:DEST_DIR)
[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*