0

次の値を 1 つだけ含むlocal.propertiesファイルがあります。

student.id=100

の値を1ずつ増やす次のAnt スクリプトを作成しました。student.id

 <target name="increase-id">
    <!-- student.id is increased by 1, no problem -->
    <propertyfile file="local.properties">
         <entry key="student.id" type="int" operation="+" value="1" />
     </propertyfile>

     <!--The following echo always show me "Student ID: 1, why?"-->
     <echo message="Student ID: ${student.id}"/>
 </target>

command を実行するたびに、local.propertiesファイルant increase-idの値が1 ずつ増えます。ここでは問題ありません。しかし、メッセージには常に「なぜ? 」と表示されます。student.id<echo>Student ID: 1

4

1 に答える 1

1

これは私のために働きます:

<project name="increase.test" default="increase-id">

    <target name="increase-id">

        <!-- documentation says that this task is for editing property files -->
        <propertyfile file="local.properties">
            <entry key="student.id" type="int" operation="+" value="1" />
        </propertyfile>

        <!-- so you should load this property after edit -->    
        <property file="local.properties" />
        <echo message="Student ID: ${student.id}"/>

    </target>

</project>

ちなみに、相対パスは使用しないでください。これの代わりに、常に絶対パスを使用してください。build.xml と同じディレクトリにあるプロパティ ファイルをロードする場合は、<dirname/>タスクを使用できます。

<dirname property="build.dir" file="${ant.file.<projectName>}"/>,

どこ:

  1. ${ant.file}現在実行中の build.xml を示す組み込みプロパティです。
  2. <projectName>は単なるプロジェクト名です

    ${ant.file.<projectName>このパターンのみを使用する場合は${ant.file}メイン ビルドを示すため、常にこのパターンを使用して dirname を作成するようにしてください。たとえば、他のビルドを実行するビルドがあり、他のビルドで使用する場合、${ant.file}それはメインビルドに示されます。明確でない場合は、Apache ant のドキュメントを読んで、簡単なビルドを作成してみてください。

于 2013-03-18T14:00:28.663 に答える