ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Doug Brown" <>
Subject RE: Passing command line parameter to ant and reading them from within JUnit
Date Wed, 12 Feb 2003 23:32:12 GMT
If you invoke ant like this:

    ant -Dfoo=123

in your build.xml file you just dereference it as if it was already defined.

    <property name="bar" value="${foo}"/>

Here's a more complicated example that specifically tests to see whether
something was defined before continuing:

  <target name="">
    <condition property="foo.ok">
      <isset property="foo"/>
    <fail message="The 'foo' property is not set" unless="foo.ok"/>

Then you just make your other targets depend on this first. If "foo" isn't
defined, everything stops and the user gets a message. Of course, you can
also do something like this:

  <target name="check.isset" if="foo">
    <echo message="foo is set"/>
  <target name="check.isnotset" unless="foo">
    <echo message="foo is not set"/>
  <target name="check" depends="check.isset,check.isnotset"/>

There's another thing with properties; once they are defined, they cannot be
re-defined. Therefore, you cannot check to see if a property is defined and
if not, define it. But you can get around this in two ways:

1) Just go ahead and set a property within the build.xml file without
checking whether it was already defined. If the property was defined on the
ccommandline, the commandline value is the one that will be used. If it's
not defined on the commandline, the build.xml property definition will win.

2) Check to see whether the property was defined and use that property to
set a different property altogether.


-----Original Message-----
From: Steve [] 
Sent: Wednesday, February 12, 2003 3:04 PM
Subject: Passing command line parameter to ant and reading them from within


I know how to pass command line parameters into ANT using the -D option.
But how can I pick up these parameters from within a JUnit test script
Started from within ANT.



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message