[ACCEPTED]-adding non-code resources to jar file using Ant-jar

Accepted answer
Score: 40

You shouldn't have an includesfile attribute in a target to 12 start with, and I suspect you've misunderstood 11 the point of it anyway - the idea is that 10 the file you specify with includesfile contains patterns 9 for which files to include, if you don't 8 want to put them into your Ant file.

It strikes 7 me that all you need is an extra fileset 6 containing the appropriate files you need. For 5 example, for readthis.txt:

<target name="distribute" depends="compile">
  <jar destfile="${distributionDir}/myjar.jar" >
    <fileset dir="${outputDir}"/>
    <fileset dir="${sourceDir}"/>
    <fileset file="readthis.txt" />
  </jar>
</target>

I would also suggest that 4 you create a new directory for the resources, so 3 you can do:

<target name="distribute" depends="compile">
  <jar destfile="${distributionDir}/myjar.jar" >
    <fileset dir="${outputDir}"/>
    <fileset dir="${sourceDir}"/>
    <fileset dir="${resourcesDir}" />
  </jar>
</target>

with no hassle. This will also 2 keep your directory structure cleaner, making 1 it easier to find things from the top downwards.

More Related questions