0

I wanted to check if a property value has a value which is supposed to be read from another file in ant

can any body please without an additional jar.

<property name="a" value="${input.password}" />

wanted to check if input.password has got the value or not from xyz.properties file or not

many thanks Jib

P.S: Actually I have to check this line password=mypassword is exist in .properties file or not with ant script. Another way is welcome !

Edit: I am doing from one of the referenced solutions but not succeeding:

<property file="..\..\xyz\application.properties" prefix="input" /> 

<property name="foo" value="${input.password}"/>
 <fail message="Property &quot;foo&quot; has no value">
     <condition>
          <not>
             <equals arg1="${foo}" arg2=""/>
          </not>
     </condition>
</fail>

Always getting this message:"Property "foo" has no value" regardless of this line exists or not:password=de in application properties.

static void main
  • 728
  • 2
  • 9
  • 34

2 Answers2

1

you can try using the <fail message="db.schema is not defined!" unless="db.schema"/> block this for example will fail if db.schema is not defined. You might find some of this and useful, is this what you're looking for?

Check this too. Oh OK I see what you mean now, please try this (I'm using Ant 1.8.2): this is build.xml :

<project name="Bla" default="build" basedir=".">
<target name="build">
    <property file="bla.properties"/>

<fail>
     <condition>
       <not>
        <equals arg1="${foo}" arg2="bodo"/>
       </not>
     </condition>
</fail>
</target>
</project>

The file bla.properties contains foo=boo, and it currently fails, if I change bodo to boo, is succeeds.

Community
  • 1
  • 1
Scis
  • 2,934
  • 3
  • 23
  • 37
  • so far I didn't get the answer of my question. I have tried all the solutions referenced; but none of them is working. – static void main Sep 07 '12 at 14:27
  • yes definitely the property has value; but the value got the value or not that needs to be checked :. This above check a exist or not or it has value so yes but that is not what i want (correct me if I am wrong): – static void main Sep 07 '12 at 14:48
1
<project name="demo" default="dosomething">

    <loadproperties srcFile="check.properties"/>

    <target name="check">
        <input message="Enter value" addproperty="input"/>

        <condition property="input.matches">
            <equals arg1="${input}" arg2="${valuefromfile}"/>
        </condition>
    </target>

    <target name="dosomething" depends="check" if="input.matches">
        <echo message="hello world"/>
    </target>

</project>
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185