Java 使用Ant条件标记
我想做这样的事情Java 使用Ant条件标记,java,ant,ant-contrib,Java,Ant,Ant Contrib,我想做这样的事情 <target name="init" description="Create build directories. > <mkdir dir="bin" /> <mkdir dir="dist" /> <!-- Check for the presence of dependent JARs --> <condition property="depen
<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>
您需要让jar在运行时可见,或者按照链接中的描述正确配置它
事情归结起来就是让Ant加载任务定义,因此如果您将Ant contrib
放入Ant/lib,您只需要
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
只是一个建议。对于ant 1.9.1及以后的版本,您可以在没有ant contrib()的情况下使用if/除非执行相同的操作
你的目标是
<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>
给出的解决方案肯定会对您有所帮助。
<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>