• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Ant zip task - include empty directories, and subdirectories

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All,

I've been driving myself insane trying to figure this one out - and going nuts with web searches. All to no avail.

First off, I am using ANT version 1.8.2, so I don't have the 1.6.2 issues with zip and empty folders.

I am trying to create a zip file, and my script so far is as follows:



So, what this does is take the jar file that exists in {dist} and add it to the zip file, so that when it's unzipped, the jar file comes out directly, and does NOT maintain the hierarchy (ie: doesn't create a {dist} directory and put the jar file inside it). This is the behavior I want so far.

HOWEVER, I would like to know how to do the following:
- include a {config} directory and ALL the files within it except for one called "test-config.xml"
- include two separate empty directories - say {subdir1} and {subdir2}. They may or may not have files in them, but I do NOT want ANY files in those directories when they get zipped.

For that second part with the empty directories, I'm perfectly content having the zip task create those in the zip itself without necessarily creating them on the local file system. In fact, the ideal would be if they'd be in the zip file and NOT be on the local file system - but I'll take whatever method I can get that works.

So, my local file system will look like so:

dist/MyJar.jar
config/config1.xml
config/config2.xml
config/test-config.xml
subdir1/ (may or may not exist and may or may not have files in it)
subdir2/ (may or may not exist and may or may not have files in it)


I want the ZIP file, when unzipped, to result in:
MyJar.jar
config/config1.xml
config/config2.xml
subdir1/
subdir2/


How do I accomplish this? I've tried variants of fileset, dirset, zipfileset, and am failing at every attempt.

Thanks in advance...
 
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could run a script after the unzip that creates the empty directories you need. You may also file a bug against the Ant code. Some old Ant code may have snuck back into the code stream.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where are all of these files located before doing the zip? If they are spread out across the project's director structure, you will have to provide a <zipfileset> tag for each location. For example, something like this:



Another method, which I prefer, is to first use the <code> task to copy everything I want in the zip file to a common base directory and then zip up the base directory. I usually put those two tasks in two different targets, that way I can just build the directory structure, or just zip the files in the directory.
 
Joe Vahabzadeh
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
D'oh! I couldn't see the forest for the trees...

I don't know what the "code" task is - but I assume you just meant to have another target in the build file that creates the structure that I wanted to exist in the zip file. I'm going to go with that method, it seems cleaner.

Seems way simpler now that I'm not trying to hammer a square peg into a round hole!

(it doesn't help that I actually was also screwing up my directory name property values . . having a name/location pair is great for setting up absolute directory paths, but using relative paths with the same name, I had to use name/value - forgot that little tidbit and drove myself batty in the process)
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ooops, typo. <code> should be <copy>
 
reply
    Bookmark Topic Watch Topic
  • New Topic