2012-04-27 59 views
3

すべてに含まれ、Path要素条件

は、誰かがディレクトリが存在する条件付きであれば、パス要素にディレクトリを含める方法に助けてください:だから

<path id="lib.path.ref"> 
    <fileset dir="${lib.dir}" includes="*.jar"/> 
    <path location="${build.dir}" if="${build.dir.exist}" /> 
</path> 

以下のようにこれは現在ので動作しません。 path要素はif属性をサポートしていません。私の場合は、build.dirが存在する場合にのみincludeします。 Ant-Contribまたは類似のAntの拡張機能をインストールすることなく

おかげ

+0

あなたのためにこれを見つけました:http://stackoverflow.com/questions/666718/need-to-set-path-cp-in-ant-script-depending-on-value-of-a-property may助けてください。 – htulsiani

答えて

3

を、次のようなXMLであなたが望むものを達成することができます

<project default="echo-lib-path"> 
    <property name="lib.dir" value="lib"/> 
    <property name="build.dir" value="build"/> 
    <available file="${build.dir}" type="dir" property="build.dir.exists"/> 

    <target name="-set-path-with-build-dir" if="build.dir.exists"> 
     <echo message="Executed -set-path-with-build-dir"/> 
     <path id="lib.path.ref"> 
      <fileset dir="${lib.dir}" includes="*.jar"/> 
      <path location="${build.dir}" /> 
     </path> 
    </target> 

    <target name="-set-path-without-build-dir" unless="build.dir.exists"> 
     <echo message="Executed -set-path-without-build-dir"/> 
     <path id="lib.path.ref"> 
      <fileset dir="${lib.dir}" includes="*.jar"/> 
     </path> 
    </target> 

    <target name="-init" depends="-set-path-with-build-dir, -set-path-without-build-dir"/> 

    <target name="echo-lib-path" depends="-init"> 
     <property name="lib.path.property" refid="lib.path.ref"/> 
     <echo message="${lib.path.property}"/> 
    </target> 
</project> 

ここで重要な部分は-initターゲットに何が起こるかです。 -set-path-with-build-dir-set-path-without-build-dirターゲットに依存しますが、Antは、build.dir.existsが設定されているかどうかに基づいて1つのターゲットだけを実行します。

利用可能なタスクの詳細については、http://ant.apache.org/manual/Tasks/available.htmlを参照してください。

+0

明快で簡潔な作業ソリューションを提供するために時間をとっていただきありがとうございます。このコミュニティを気に入ってください。 – Afamee

関連する問題