tags:

views:

554

answers:

2

Hi,

I've got an ant jar task:

<target name="jar">
    <jar destfile="${generated.jars.dir}/hello-${environment}.jar">
     <fileset dir="${generated.classes.dir}"/>
     <fileset dir="${environment.dir}/${environment}" includes="config.xml"/>
    </jar>
</target>

How can I force the config.xml file to be pushed to a specific directory in the jar rather than at the root level, say in /database/config.xml or something like that...

PS: The reason for doing this is that I can have a hello-local.jar, hello-dev.jar, hello-qa.jar, etc.

+2  A: 

You want zipfileset:

<zipfileset dir="${environment.dir}/${environment}" includes="config.xml" prefix="database"/>

or:

<zipfileset dir="${environment.dir}/${environment}" includes="config.xml" fullpath="database/config.xml"/>
bkail
so if I understand you correctly, you're suggesting that after the jar has been created to stuff in the config file through zip?
Stephane Grenier
No, since the <jar> task extends the <zip> task it supports nesting zipfileset and zipgroupfileset directly.
+3  A: 

use zipfileset like this:

    <jar destfile="${generated.jars.dir}/hello-${environment}.jar">
        <fileset dir="${generated.classes.dir}"/>
        <zipfileset dir="${environment.dir}/${environment}" 
                includes="config.xml" fullpath="database/config.xml"/>
    </jar>
kaboom