adding non-code resources to jar file using Ant

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

It strikes me that all you need is an extra fileset containing the appropriate files you need. For 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 you create a new directory for the resources, so 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 keep your directory structure cleaner, making it easier to find things from the top downwards.

Leave a Comment