How can i include .properties, .xml and other resource files while compiling the source code of a project using Ant? Here is my build file:
<?xml version="1.0"?>
<project name="NmzAzzist" basedir="." default="main">
<property name="src.dir" value="Source/Myproj" />
<property name="build.dir" value="ReleaseBuild/classes" />
<property name="jar.dir" value="ReleaseBuild" />
<path id="master-classpath">
<fileset dir="lib">
<include name="*.jar" />
</fileset>
</path>
<target name="clean" description="Clean output directories">
<delete dir="${build.dir}" />
</target>
<target name="build" description="Compile source tree java files">
<echo>Compiling the source code</echo>
<mkdir dir="${build.dir}" />
<javac destdir="${build.dir}" source="1.5" target="1.5" includeantruntime="false">
<compilerarg value="-Xlint:unchecked" />
<src path="${src.dir}" />
<classpath refid="master-classpath" />
</javac>
</target>
<target name="jar" depends="build">
<mkdir dir="${jar.dir}" />
<echo>building jar!</echo>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="com.ushustech.nmsazzist.NMSAzzistApp" />
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true" />
</target>
<target name="main" depends="clean,run" />
</project>
Right now my build is only compiling the Java files and producing classes. But I have some property and XML files in various folders (including the source folders), that I would like included in the output directory, that are not getting placed there now. I appreciate any suggestions in accomplishing this task.
properties is a file extension for files mainly used in Java-related technologies to store the configurable parameters of an application. They can also be used for storing strings for Internationalization and localization; these are known as Property Resource Bundles.
Copy those resources file before running jar
task.
<copy todir="${build.dir}">
<fileset dir="${src.dir}">
<exclude name="**/*.java"/>
</fileset>
</copy>
This would do the trick:
<target name="dist" depends="compile">
<echo>packaging classes</echo>
<jar jarfile="${dist.dir}/${project.distname}.jar" basedir="${build.dir}">
<fileset dir="${src}">
<include name="*.properties" />
</fileset>
</jar>
</target>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With