How do I optionally require a command line argument for Ant?

I'm new to ant, and I want to require a file name if something other than the default target is used, so the call syntax would be something like this:

ant specifictarget -Dfile=myfile

I use ant contrib to give me extra functionality, so I have this:

<if>
    <equals arg1="${file}" arg2="" />
     <then>
        <!-- fail here -->
     </then>
</if>

I believe that if the file is not specified, it can be equal to an empty string. Obviously, this did not work, and I did not find any examples on Google or the correct syntax in the manual.

What syntax should I use?

+3
source share
4 answers

contrib. ant, if/except . . :

<target name="check" unless="file" description="check that the file property is set" >
    <fail message="set file property in the command line (e.g. -Dfile=someval)"/> 
</target>

<target name="specifictarget" if="file" depends="check" description=" " >
    <echo message="do something ${file}"/> 
</target>
+6

.

ant specifictarget -Dfile=myfile

Ant . , ,

<property name="file" value=""/>

. , , .

+3

Ant, :

<property name="file" value="" />

file , ​​ . , .

+2

escape-, ant , .

     <if>
       <equals arg1="${file}" arg2="$${file}" />
       <then>
         <echo>BARF!</echo>
       </then>
     </if>
+1

Source: https://habr.com/ru/post/1716912/


All Articles