You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by "Craig R. McClanahan" <Cr...@eng.sun.com> on 2000/04/03 02:31:39 UTC

System Properties versus properties from build.xml

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

Re: System Properties versus properties from build.xml

Posted by Costin Manolache <co...@eng.sun.com>.

James Duncan Davidson wrote:
> 
> > 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.
> 
> Yep. That was intended behavior. If it doesn't work that way then it's way
> busted.

This one was breaking the nightly builds - I fixed it (again) few days 
ago, it should work now.
( i.e. -Dproperty=value should override the properties in project - note 
that you can use both
java system properties or define ant properties, i.e.
java org.apache.tools.ant.Main -Dproperty=value
)

Costin


Re: System Properties versus properties from build.xml

Posted by James Duncan Davidson <ja...@eng.sun.com>.
> 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.

Yep. That was intended behavior. If it doesn't work that way then it's way
busted.

.duncan


Re: System Properties versus properties from build.xml

Posted by Kevin Riff <ke...@earthling.net>.
Try "java org.apache.tools.ant.Main
-Dservlet.jar=/real/path/to/servlet.jar". In other words, specify the -D
switch as an argument to Ant, not to the JVM. This has worked for me.


"Craig R. McClanahan" wrote:

> 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