Ian Robertsが既に述べたように、Ant-Contrib jar が必要で、<taskdef/>
この jar を指すように をセットアップします。プロジェクト内に配置し、バージョン管理システムにチェックインすることを強くお勧めします。このようにして、誰かがあなたのプロジェクトをチェックアウトするとき、彼らは既に Ant-Contib.jar をインストールしています。
私の標準は、ビルドに必要なすべてのオプションの jar (コンパイルに必要な jar ではない) をディレクトリ${basedir}/antlib
に配置し、次にオプションの各 jar を独自のディレクトリに配置ant-contrib-1.0b3.jar
すること${basedir}/antlib/antcontrib
です。
次に、タスクを次のように定義します。
<property name="antlib.dir" value="${basedir}/antlib"/>
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<fileset dir="${antlib.dir}/antcontrib"/>
</classpath>
</taskdef>
このように、jar ファイルを新しいバージョンの Ant-Contrib jar に更新する場合は、それをディレクトリにプラグインするだけです。を更新する必要はありませんbuild.xml
。
net/sf/antcontrib/antlib.xml
また、私は and を使用しないことに注意してくださいnet/sf/antcontrib/antcontrib.properties
。XMLファイルを使用する必要があります。この手順はタスク ページにあり、メイン ページのインストール手順とは異なります。その理由は、XML ファイルには<for>
タスクの正しい定義が含まれていますが、プロパティ ファイルには含まれていないためです。
ただし、 Ant 1.9.1 には、オプションの jar ファイルを必要if
としない別の方法があります。unless
これらは新しいIfおよびUnlessエンティティ属性です。
これらはすべてのタスクまたはサブエンティティに配置でき、通常は Ant-Contrib のif/else
ものを置き換えることができます。
<target name="move">
<available file="${output.dir}" type="dir"
property="output.dir.exists"/>
<echo message"Directory exists"
if:true="output.dir.exists"/>
<move file="${output.dir}" tofile="${output.dir}_1"
if:true="output.dir.exists"/>
<property name="newdirectory" value="${dest}"
if:true="output.dir.exists"/>
<echo message="Directory does not exists"
unless:true="output.dir.exists"/>
<move file="${newdirectory}" todir="C:\reports" />
</target>
あなたの例ほどきれいではありません。ただし、代わりにターゲット名にif=
andunless=
パラメータを使用します。
<target name="move.test">
<available file="${output.dir}" type="dir"
property="output.dir.exists"/>
</target>
<target name="move"
depends="move.test, move.exists, move.does.not exists">
<move file="${newdirectory}" todir="C:\reports" />
</target>
<target name="move.exists"
if="output.dir.exists">
<echo message="Directory exists" />
<move file="${output.dir}" tofile="${output.dir}_1"/>
<property name="newdirectory" value="${dest}"/>
</move.exists/>
<target name="move.does.not.exists"
unless="output.dir.exists"/>
<echo message="Directory does not exist" />
</target>
すべてをエコーしなかった場合、構造は少しきれいになります。
<target name="move.test">
<available file="${output.dir}" type="dir"
property="output.dir.exists"/>
</target>
<target name="move"
depends="move.test, backup">
<move file="${newdirectory}" todir="C:\reports" />
</target>
<target name="backup"
if="output.dir.exists">
<move file="${output.dir}" tofile="${output.dir}_1"/>
<property name="newdirectory" value="${dest}"/>
</move.exists/>