ѕтƒ
ѕтƒ

Reputation: 3637

Including .properties files while building a project using ant

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.

Upvotes: 8

Views: 9030

Answers (2)

aura
aura

Reputation: 11

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>

Upvotes: 1

Fu Cheng
Fu Cheng

Reputation: 3395

Copy those resources file before running jar task.

<copy todir="${build.dir}">
    <fileset dir="${src.dir}">
       <exclude name="**/*.java"/>
    </fileset>
</copy>

Upvotes: 10

Related Questions