File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ant, Maven and Other Build Tools and the fly likes unzipping jars 'where they stand' 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 "unzipping jars Watch "unzipping jars New topic

unzipping jars 'where they stand'

Righteous Raven

Joined: Apr 24, 2003
Posts: 4
I need to unzip a whole bunch of jars which are contained within a directory tree, but I want to preserve the location of the jars, as well as the structure of the files within the jars.
For example, say i have 2 jars:
/a/b/first.jar and
now i want to unzip them such that the contents of first.jar end up in /a/b/ while the contents of second.jar end up in /a/c/. (note that 2 separate zip commands doesnt work, cause in reality i have 100 jars)
The command:
<fileset dir="/a" />
doesnt work because it would extract the contents of both first.jar and second.jar to the /a/ directory.
One solution is to have a class that recursively searches through the directory tree and executes its body on every dir that matches a patternset.. but i dont know if that exists or not.
Any suggestions?
Greg Charles

Joined: Oct 01, 2001
Posts: 2968

Standard Ant doesn't provide any loop syntax, and rightfully so. It's not meant to be a programming language. However, much of the need for looping would be reduced if you could take a fileset or patternset and have a task act on each member individually ... maybe by using an antcall. Sometimes the tasks you want don't support filesets, and sometimes (as with unjar) they interpret them differently from what you need.
The bad news is I can't think of anyway to do accomplish this in the current Ant. However, we've identified a gap that could conceivably be filled. Some day, I'm going to learn how to develop Ant tasks on my own. In the meantime, you could try submitting your idea to the Ant team.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Try this unzip syntax.

Regards, Rene Larsen
Dropbox Invite
Greg Charles

Joined: Oct 01, 2001
Posts: 2968

Ah, but the point is not to unjar a single jar file in place, but to unjar all the jar files in a fileset, with different destinations as determined by where the jar is found.
As another example, I run Castor to convert a series of XML schemas (XSD files) to classes. I've written a parameterized task that executes the Castor compiler:

I can call this target with antcall:

However, every time I add a new schema, I have to go into the build.xml and write another antcall task. It would be nice if I could just find all the XSD files in the schema directory and run Castor on them. Of course, I'd still need a way to derive the package name to use, but I think that would be possible. My point is that often it would be nice to execute a target individually on each of the files in a fileset. Right now, I can't think of any way to do that.
Righteous Raven

Joined: Apr 24, 2003
Posts: 4
hmmm... I guess this means I'll be writing my own class... <sigh>
I agree. Here's the link:
subject: unzipping jars 'where they stand'
jQuery in Action, 3rd edition