ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glenn McAllister <>
Subject Re: Question about properties and ant2
Date Wed, 12 Sep 2001 13:16:19 GMT
Peter Donald wrote:

> On Wed, 12 Sep 2001 05:34, Claudio Corsi wrote:
> > This said, then how would I go about including a variable within the xml
> > file that is immutable and can be used throughout the xml file? If this
> > does not exist, can something like this be implemented? This can be for
> > ant1 or ant2.
> I think you mean mutable (ie changeable) not immutable. The only real way to
> do this today is via antcall and setting parameters in the antcall. Antcall
> actually creates a new Project instance and optionally populates it with
> property values again.

Actually, there is another way (and I'm not talking about using the XML ENTITY

Since data types like patternset, fileset and path can now be defined inside of
targets with id's, you can create "generic" targets that make used of those
"named" data types.  Here's a simple, vastly truncated example:

<property name="build.base" value="build" />
<property name="src.base" value="src" />
<property name="" value="${src.base}/java" />

<!-- usually its not a great idea to include your
     third-pary libs in your repository, but I'm doing
     this for illustrative purposes
<property name="src.lib" value="${src.base}/lib" />

<target name="build">
  <mkdir dir="${build.classes}" />

  <javac srcdir="${}"
    <classpath refid="classpath" />
    <patternset refid="packages" />

<target name="build-my-subproject"
        depends="prepare-my-subproject,build" />

<target name="prepare-my-subproject">
  <property file="" />
  <property file="" />

  <patternset id="required_jars">
    <include name="log4j.jar" />

  <patternset id="packages">
    <include name="com/some/company/myproject/*" />
    <include name="com/some/company/util/*" />

  <path id="classpath">
    <fileset dir="${src.lib}">
      <patternset refid="required_jars" />

Contents of

Name=My Project

Contents of


So, every time you want to create a new subproject build you need to add two
targets (prepare-new-subproject, build-new-subproject), define a number of
patternsets and paths in the prepare- target, and add a new properties file.

The nice part about this layout is that you don't need near as many <antcall>
tasks; I find <antcall> to be a bit heavyweight for me.  The big place where you
do need antcall is in a build-all type target:

<target name="build-all">
  <antcall target="build-subproject1" />
  <antcall target="build-subproject2" />
  <!-- ... etc... -->

Hope that helps a bit.

Glenn McAllister
SOMA Networks, Inc.
View raw message