The Artima Developer Community
Sponsored Link

Java Buzz Forum
Gravy: Using Ant from Groovy for short non-build scripts

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
dion

Posts: 5028
Nickname: dion
Registered: Feb, 2003

Dion Almaer is the Editor-in-Chief for TheServerSide.com, and is an enterprise Java evangelist
Gravy: Using Ant from Groovy for short non-build scripts Posted: Jun 22, 2005 11:41 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by dion.
Original Post: Gravy: Using Ant from Groovy for short non-build scripts
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
Latest Java Buzz Posts
Latest Java Buzz Posts by dion
Latest Posts From techno.blog(Dion)

Advertisement

I recently had to whip out a one/few-off script that took a directory, and recursively grabbed jar files from it, and put all of the classes in one place. I looked at JarJar and Uberjar, but in the end it was easier to whip together a few lines of Groovy to make it happen (although I could have used Ruby, JavaScript/Rhino, Perl, etc etc).

When it came to jar'ing and unjaring files, instead of using the Java APIs, it was easier to just use ant via the AntBuilder. This allowed me in one simple line to use the tasks available there:

ant.unjar(src: file.path, dest: structure[typeOfJar].outputDir)
Very convenient. This isn't using Ant in a more formal "I am driving the build from Groovy" way, but rather being pragmatic and thinking "oh there is a simple ant task that already does this, so lets just call into it".

Example

def buildJar(String typeOfJar) {
	println "Building a jar file for the type: $typeOfJar"
	new java.io.File(structure[typeOfJar].dir).eachFileRecurse { file ->
		try {
			//println file.path
			if (file.path =~ "\\.jar") {
				println "jar xf $file.path $structure[typeOfJar].outputDir";
				ant.unjar(src: file.path, dest: structure[typeOfJar].outputDir)
			}
		} catch (Exception e) {
			println e
		}
	}

	ant.jar(destfile: structure[typeOfJar].jar, basedir: structure[typeOfJar].outputDir)
	ant.delete(dir: structure[typeOfJar].outputDir)
}

Read: Gravy: Using Ant from Groovy for short non-build scripts

Topic: Portlet Integration Previous Topic   Next Topic Topic: Links for 2005-06-12 [del.icio.us]

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use