<project name="JavaDemo" basedir="." default="rebuild-run">

    <property name="src.dir"     value="src"/>

    <property name="lib.dir"     value="${jarDir}"/>
    <property name="mmdeploy.dir"  value="../../csrc/mmdeploy/apis/java"/>
    <path id="classpath">
        <fileset dir="${lib.dir}" includes="**/*.jar"/>
        <path path="${mmdeploy.dir}" />
    </path>

    <property name="build.dir"   value="build"/>
    <property name="classes.dir" value="${build.dir}/classes"/>
    <property name="jar.dir"     value="${build.dir}/jar"/>

    <property name="main-class"  value="${taskName}"/>


    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>

    <target name="compile">
        <mkdir dir="${classes.dir}"/>
        <javac includeantruntime="false" srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
    </target>

    <target name="jar" depends="compile">
        <mkdir dir="${jar.dir}"/>
        <jar destfile="${jar.dir}/${taskName}.jar" basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="${main-class}"/>
            </manifest>
        </jar>
    </target>

    <target name="run" depends="jar">
        <java fork="true" classname="${main-class}">
            <sysproperty key="java.library.path" path="${libDir}"/>
            <classpath>
                <path refid="classpath"/>
                <path location="${jar.dir}/${taskName}.jar"/>
            </classpath>
            <arg line="${command}" />
        </java>
    </target>

    <target name="rebuild" depends="clean,jar"/>

    <target name="rebuild-run" depends="clean,run"/>

</project>
