我无法执行if
任务。 我的代码是:无法在build.xml中添加if块
<?xml version="1.0" ?>
<project default="main">
<property name="buildsequence.property.file.fullpath" value="D:\testant\AntExample" />
<target name="main" depends="compile, compress" description="Main target">
<echo>
Building the .jar file.
</echo>
</target>
<target name="compile" description="Compilation target">
<javac srcdir="src/org" destdir="src/org" fork="yes" executable="C:\Program Files\Java\jdk1.7.0_60\bin\javac"/>
</target>
<target name="compress" description="Compression target">
<jar jarfile="Project.jar" basedir="src/org" includes="*.class" />
<if>
<available file="${buildsequence.property.file.fullpath}" />
<then>
<echo message="File exist"/>
</then>
<else>
<echo message="File do not exist" />
</else>
</if>
</target>
</project>
错误:
Buildfile: D:\projects\Self\AntExample\build.xml
compile:
[javac] Compiling 1 source file to D:\projects\Self\AntExample\src\org
compress:
BUILD FAILED
D:\projects\Self\AntExample\build.xml:19: Problem: failed to create task or type if
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
注:文件存在于D:\testant\AntExample
。
使用if任务不是ant方式。蚂蚁的方法是根据这个目标制定一个目标验证和其他目标,并且只有在'除非'属性被设置为真的情况下才会触发'if'或''。请参阅https://ant.apache.org/manual/targets.html –