ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bryan Richardson" <btri...@gmail.com>
Subject Need help calling one build file from another
Date Wed, 21 May 2008 21:55:08 GMT
Hello all,

I'm having trouble calling one build file from another.  I'm using Eclipse,
and I have two projects:

Foo
Bar

Each project has a build.xml file, and the Bar project depends on a jar file
generated by the Foo project.  The following is the build.xml file for
project Foo:

<project name="Foo" basedir=".">
    <description>Build file for Foo project.</description>

    <property name="src.dir"      location="${basedir}/src"           />
    <property name="build.dir"    location="${basedir}/build"         />
    <property name="class.dir"    location="${basedir}/build/classes" />
    <property name="dist.dir"     location="${basedir}/dist"          />
    <property name="dist.src.dir" location="${basedir}/dist/src"      />
    <property name="lib.dir"      location="${basedir}/lib"           />

    <path id="dependency.path">
        <fileset dir="${lib.dir}" includes="**/*.jar" />
    </path>

    <target name="init" depends="clean">
        <mkdir dir="${class.dir}"    />
        <mkdir dir="${dist.src.dir}" />
    </target>

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

    <target name="compile" depends="init">
        <javac destdir="${class.dir}" classpathref="dependency.path"
debug="on">
            <src path="${src.dir}" />
        </javac>
    </target>

    <target name="archive" depends="compile">
        <jar destfile="${dist.dir}/foo.jar" basedir="${class.dir}" />
    </target>
</project>

The following is the build.xml file for project Bar:

<project name="Bar" basedir=".">
    <description>Build file for Bar project.</description>

    <property name="src.dir"      location="${basedir}/src"           />
    <property name="build.dir"    location="${basedir}/build"         />
    <property name="class.dir"    location="${basedir}/build/classes" />
    <property name="dist.dir"     location="${basedir}/dist"          />
    <property name="dist.src.dir" location="${basedir}/dist/src"      />
    <property name="lib.dir"      location="${basedir}/lib"           />

    <path id="dependency.path">
        <fileset dir="${lib.dir}" includes="**/*.jar" />
    </path>

    <target name="init" depends="clean">
        <mkdir dir="${class.dir}"    />
        <mkdir dir="${dist.src.dir}" />
    </target>

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

    <target name="archive-all">
        <ant dir="../Foo"     target="archive" />

        <antcall target="archive" />
    </target>

    <target name="compile" depends="init">
        <copy file="../Foo/dist/foo.jar" todir="lib" />
        <javac destdir="${class.dir}" classpathref="dependency.path"
debug="on">
            <src path="${src.dir}" />
        </javac>
    </target>

    <target name="archive" depends="compile">
        <jar destfile="${dist.dir}/bar.jar" basedir="${class.dir}" >
            <manifest>
                <attribute name="Class-Path" value="lib/foo.jar" />
            </manifest>
        </jar>
    </target>
</project>

The problem occurs when the Bar project's build.xml calls the Foo project's
build.xml file in the archive-all target.  I get an error in the Foo
project's build.xml file in the compile target.  When I run the Bar
project's build.xml file through Eclipse's debugger with a break point at
the javac element in the Foo project's build.xml file, I notice that all of
the properties in the Foo project's build.xml file are referencing the Bar
project's path... I checked the basedir property for the Foo project's
build.xml file to make sure it was being overrided with the dir attribute of
the ant element in the Bar project's build.xml file and it is.  However,
when I look at the properties defined in the Foo project's build.xml file in
the debugger (src.dir, etc) I notice that they are referencing directories
in the Bar project and not the Foo project ("${basedir}/src" for example
doesn't seem to be working).

After all that, can anyone tell me what I'm doing wrong?  Let me know if I
need to clarify anything... :)

--
Thanks!
Bryan

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message