I used to build a jar file (or any zip-format file: war, ear, etc.),
which contents are extracted from other zip files.  For instance,
zip file src.zip contains:

+---main
|   \---org
|       \---apache
|               Test.java
|
\---test

I just want the subtree under "main" (not include main directory) to be
packed into my jar file:

+---org
    \---apache
            Test.java

So I wrote a build.xml to do this:

<project default="src-jar">
    <target name="src-jar">
        <jar destfile="my-src.jar">
            <zipfileset src="src.zip" includes="main/"/>
        </jar>
    </target>
</project>

But the result is not as expected:

+---main       // I don't want this directory here
    \---org
        \---apache
                Test.java

In order to take off the "main" directory, I modified some Ant classes. 
Attachment is the patch file from Ant 1.7.0 source.

Usage:

<project default="src-jar">
    <target name="src-jar">
        <jar destfile="my-src.jar">
            <!-- basedir instead of includes -->
            <zipfileset src="src.zip" basedir="main/"/>
        </jar>
    </target>
</project>

This is not the best solution I think.  Because it doesn't support tasks
other than "zip", "jar", "war".  For example, the following build script
won't work:

<project default="copy-src">
    <target name="copy-src">
        <copy destfile="srcdir">
            <zipfileset src="src.zip" basedir="main/"/>
        </copy>
    </target>
</project>

I suggest to improve class org.apache.tools.zip.ZipFile to support new zip
file format like "src.zip!/main".  By this way, any tasks use zipfileset
do not need to be changed.

For example,

<project default="copy-src">
    <target name="copy-src">
        <copy destfile="srcdir">
            <zipfileset src="src.zip!/main" includes="**/*.java"/>
        </copy>
    </target>
</project>

Michael Zhou <[EMAIL PROTECTED]>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to