How can I include data text files in a jar using Ant?

夙愿已清 提交于 2019-12-19 02:31:19

问题


In my src folder there is another folder called data which contains files data1.txt and data2.txt. The application loads a graph from these files in the initialization, so I want to include these files in my final jar. I use Ant to produce the jar file.


回答1:


Example from http://ant.apache.org/manual/Tasks/jar.html :

  <jar destfile="${dist}/lib/app.jar">
    <fileset dir="${build}/classes"/>
    <fileset dir="${src}/resources"/>
  </jar>

So basically you would want to include the data-files in the same way as "resources" are included above.

From the documentation of the <jar> task:

It is possible to refine the set of files that are being jarred. This can be done with the includes, includesfile, excludes, excludesfile and defaultexcludes attributes.




回答2:


Copy the files to your classes directory, where they will be included into the jar.

enter code here

<target name="copyHibernateXml">
    <copy todir="classes">
        <fileset dir="${basedir}/${sourceDir}" includes="*.xml,*.csv"/>
    </copy>
</target>


来源:https://stackoverflow.com/questions/2845228/how-can-i-include-data-text-files-in-a-jar-using-ant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!