LoginSignup
9
9

More than 5 years have passed since last update.

Antのプロパティの指定方法(タスク、プロパティファイル、コマンドライン引数)

Posted at

Antでのプロパティの指定方法とその優先順位について。

  1. プロパティタスクで<property name="xxx" value="yyy" />と書く
  2. プロパティタスクで<property file="xxx.properties" />と書き、プロパティファイルにname=valueの形式で書く
  3. 実行時のコマンドライン引数で指定する
build.xml
<?xml version="1.0"?>
<project name="SimpleAnt" default="compile">
    <property file="file.properties" />
    <property name="msg" value="Hello world" />
    <target name="compile">
        <echo>${msg}</echo>
    </target>
    <target name="test" depends="compile">
        <echo>testだけど表示するだけで何もしない</echo>
    </target>
</project>

file.propertiesがないとき

> ant compile

compile:
     [echo] hello world

file.propertiesを以下の内容で作成したとき

file.properties
msg=hello from properties file

プロパティファイルが先に読まれるので、ファイルの内容が反映される

> ant compile

compile:
     [echo] hello from properties file

コマンドライン引数で指定したとき、一番最初に評価されるので、引数の内容が反映される

> ant compile -Dmsg="hello from argument"

compile:
     [echo] hello from argument
9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9