0
votes

Below is a simplified versin of a build.xml for a Java project. It completes "build" correctly (creates the correct .class files) and prints out "Finishing build". It does not, however, print out "Starting jar". What am I not understanding? The target "jar" depends on "build", so it should be run next.

Running it with target release.

<?xml version="1.0"?>
<project name="Project" basedir="." default="release">

    <!-- directories -->
    <property name="src.dir" location="src/main/java"/>
    <property name="cls.dir" location="private/classes"/>
    <property name="lib.dir" location="lib"/>

    <property name="jar.name" value="${ant.project.name}-${jar.ver}.jar"/>

    <target name="clean" description="Delete all generated files">
        <delete dir="${cls.dir}"/>
        <delete dir="${lib.dir}"/>
    </target>

    <target name="build" depends="clean">
        <mkdir dir="${cls.dir}"/>
        <javac
            destdir="${cls.dir}"
            nowarn="off"
            fork="yes"
            debug="on">
            <classpath>
                <path path="${run.classpath}"/>
            </classpath>
            <src path="${src.dir}"/>
        </javac>
        <echo message="Finishing build"/>
    </target>

    <target name="jar" depends="build">
        <echo message="Starting jar"/>
        <mkdir dir="${lib.dir}"/>
        <jar destfile="${lib.dir}/${jar.name}">
            <fileset dir="${cls.dir}"/>
            <fileset dir="${src.dir}" includes="**/*.properties"/>
            <fileset dir="${src.dir}" includes="**/*.xml"/>
        </jar>
    </target>

    <target name="release" depends="jar" description="Entry point">
    </target>

</project>
1
What is the command you use when running the target? Are you running the jar target?Java Devil
Running with release, the jar part does not run. If I run w/ jar, then jar also runs. I want jar to run when I run with release..user1145925
Try running with "ant -v" for verbose output and see if that gives you a clue.dnault
Run the command ant -d release. You may want to redirect that output to a file. The start will show you the calculation it does to figure out the dependency matrix. By the way, you should not have your build depend upon clean. You can have release depend upon clean,jar, but you want developers to be able to do a build without wiping out all class files that were built`.David W.

1 Answers

0
votes

Update the release target as follows to note that release depends on build then jar. i.e. depends="build,jar" i.e.

    <target name="release" depends="build,jar" description="Entry point">
       <echo message="release ..."/>
    </target>