There is something about the way that property setting is working that I
don't understand.

I was led to believe by the documentation, and by looking at the source
code, that properties set on the command line that invokes Ant (such as
java -Dmy.property=my.value org.apache.tools.ant.Main) would override
any value set for my.property in the build.xml file.  The behavior I'm
observing (with the current Ant source code from CVS) is exactly the
opposite -- property values from the build.xml file seem to override
system properties.

The case in point is I want to use a property named "servlet.jar" to
provide a pathname to the servlet API classes you want to compile some
stuff with, but provide a default value in the build.xml in case the
user doesn't provide the corresponding system property.  My build.xml
(in part) looks like this:

    <project name="myproject" default="compile" basedir=".">

        <target name="init">
            <property name="servlet.jar"
value="/default/path/to/servlet.jar"/>
        </target>

        <target name="compile" depends="init">
            <echo message="The property is set to ${servlet.jar}"/>
            ... compile commands ...
        </target>

    </project>

Now, even if I invoke Ant like this:

    java -Dservlet.jar=/real/path/to/servlet.jar
org.apache.tools.ant.Main

the value that is echoed is always "/default/path/to/servlet.jar", which
is not what I wanted.

Any suggestions or guidance on what I'm not understanding?

Craig McClanahan

Reply via email to