9

2 つの ant ファイルがあります。

1) メインファイル

<include file="otherFile.xml" as="otherFile"/>

<target name="firstTarget">
    <antcall target="otherFile.secondTarget"/>
</target>

2) ユーティリティファイル

<target name="secondTarget">
    <antcall target="thirdTarget"/>
</target>

<target name="thirdTarget">
     <echo message="ok"/> 
</target>

を呼び出すと、firstTargetが見つからないと表示されますthirdTarget。このように変更するとsecondTarget

<target name="secondTarget">
    <antcall target="otherFile.thirdTarget"/>
</target>

それは動作します。しかし、secondTarget を直接使用することはできません。2 番目のファイルは接頭辞 otherFile を認識していないため

4

6 に答える 6

1

直接呼び出されてインクルードされるファイルでは、次のパターンを使用します。

<project name="my-project">
  <!-- if this is the top-level build.xml, ${self} == "" -->
  <condition property="self" value="">
    <equals arg1="${ant.project.name}" arg2="my-project" />
  </condition>
  <!-- if this is an included build.xml, ${self} == "my-project." -->
  <property name="self" value="my-project." /><!-- note the trailing dot -->
  ...

次に、antcall に以下を使用します。

<antcall target="${self}target" />
于 2016-02-03T16:27:30.607 に答える
0
<import file="otherFile.xml"/>    
<target name="firstTarget">
        <antcall target="secondTarget"/>
</target>

インポート タスクを使用してファイルをアップロードします。

于 2017-01-11T11:27:51.050 に答える
0

ANTのドキュメントには次のように書かれています:

含まれるファイルごとに、Ant は含まれるビルドファイルへのパスを含むプロパティを追加します。このパスを使用すると、含まれるビルドファイルはリソースを保持し、その位置に関連してそれらを参照できます。たとえば、builddocs という名前の docsbuild.xml ファイルを含めると、メインのビルドファイルの ant.file プロパティと同様に、そのパスを ant.file.builddocs として取得できます。

これを利用して、必要なことを行うことができます。つまり、「含まれる」コンテキストまたはトップレベルのコンテキストから呼び出されているかどうかにかかわらず、antcall を機能させることができます。あなたがすべきことは、プロパティの値を「otherFile.context」に設定することです。プロパティ ant.file.otherFile が定義されている場合、そうでない場合は '' (つまり空の文字列)。そして、プロパティ展開を使用してターゲットを呼び出すことができます。例えば:

<antcall target="${otherFile.context}thirdTarget"/>

試したことはありませんが、動作しない理由はわかりません。

于 2013-11-26T20:35:31.337 に答える
-1

以下のように、同じファイルにあるターゲットに対して ant 呼び出しを行うことができます。

<target name="secondTarget">
    <antcall target="thirdTarget" antfile="${ant.file}"/>
</target>
于 2015-04-23T22:14:22.167 に答える