1

我想做这样的事情

<target name="init" description="Create build directories.
    >
    <mkdir dir="bin" />
    <mkdir dir="dist" />
            <!-- Check for the presence of dependent JARs -->
            <condition property="dependent.files.available">
               <and>
                 <available file="../../xx.jar" />
                 <available file="../../yy.jar" />
               </and>
            </condition>
</target>

<!--- Compile -->
<target name="compile" depends="init" description="Compile java sources 
    and create classes">
         <if>
           <isset property="dependent.files.available"/>
             <then>
       <javac srcdir="src" destdir="bin" classpathref="ext_jar_classpath"/>
             </then>
             <else>
                <echo message="Either xx.jar or yy.jar not found"/>
             </else>
         </if>  
</target>

当我尝试编译代码时,它给了我以下错误

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

这是正确的做法吗?

4

2 回答 2

3

您需要让ant-contribjar 在运行时可见,或者按照链接中的说明正确配置它。

事情归结为让 Ant 加载任务定义,所以如果你放入ant-contribant/lib,你只需要

<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
于 2013-08-07T17:15:16.460 回答
0

只是一个建议。从 ant 1.9.1 开始,您可以使用 if/unless 而不使用 ant-contrib ( http://ant.apache.org/manual/targets.html )做同样的事情

你的目标是

<target name="init" description="Create build directories.
    >
    <mkdir dir="bin" />
    <mkdir dir="dist" />
            <!-- Check for the presence of dependent JARs -->
            <condition property="dependent.files.available">
               <and>
                 <available file="../../xx.jar" />
                 <available file="../../yy.jar" />
               </and>
            </condition>
</target>

<!--- Compile -->
<target name="compile" depends="init" description="Compile java sources 
    and create classes" if="dependent.files.available">

       <javac srcdir="src" destdir="bin" classpathref="ext_jar_classpath"/>

</target>
于 2013-09-09T20:36:33.610 回答