adding non-code resources to jar file using Ant

前端 未结 1 766
温柔的废话
温柔的废话 2020-12-01 18:24

I am in the process of packaging my java application into a jar file. I am using ant and eclipse. I need to actually include in the jar a couple of separate, non-code files

相关标签:
1条回答
  • 2020-12-01 18:38

    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.

    0 讨论(0)
提交回复
热议问题