The java life

          My working life with java
          隨筆 - 7, 文章 - 0, 評論 - 2, 引用 - 0
          數據加載中……

          Ant conditional branch

          I was working on a auto-build file using ant when I wanted to add some conditional branches in the file.
          For example, I want to first check whether the environment variables have been set, if yes, then go on build, if not, just break the current build.
          The script is like this:
          <project name="Test Project" default="build">
          <property environment="env" />
          <target name="build" depends="path.check">
          <echo> continue build </echo>
          </target>
          <target name="path.check" depends="checkpath" unless="all.variable.set">
          <echo>env.JAVA_HOME=${env.JAVA_HOME}</echo>
          <echo>env.ECLIPSE_HOME=${env.ECLIPSE_HOME}</echo>
          <fail message="not all variables have been set or not set correctly." />
          </target>
          <target name="checkpath">
          <condition property="all.variable.set">
          <and>
          <available file="${env.JAVA_HOME}" />
          <available file="${env.ECLIPSE_HOME}" />
          </and>
          </condition>
          </target>
          </project>

          The main point of the conditional branch is the "condition" element and the "unless" attribute in the <target>. Please refer to the Apache Ant website for more information.
          In this script, we check whether the environment variable "JAVA_HOME" and "ECLIPSE_HOME" have been set, and also check whether the directory exists.

          If you only want to test whether this variables have been set, you can change the <condition> block to this:
          <condition property="all.variable.set">
              <and>
                  <isset property="env.PROMPT" />
          <isset property="env.SONIC_HOME" />
              </and>
          </condition>
          For more details about what you can do in the <condition> element, you can check here.

          posted on 2010-02-09 11:59 施德明 閱讀(360) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 共和县| 囊谦县| 海口市| 石首市| 正镶白旗| 苗栗市| 青河县| 芦溪县| 盘锦市| 东乡族自治县| 黄龙县| 鲁甸县| 凤阳县| 莒南县| 广水市| 永泰县| 邯郸市| 五寨县| 米脂县| 兰州市| 蓝山县| 舒城县| 文化| 丽江市| 温州市| 扎兰屯市| 思南县| 兴隆县| 乐至县| 额尔古纳市| 融水| 江山市| 鹤山市| 长白| 远安县| 永仁县| 台南县| 辛集市| 泰州市| 安远县| 罗田县|