The java life

          My working life with java
          隨筆 - 7, 文章 - 0, 評(píng)論 - 2, 引用 - 0
          數(shù)據(jù)加載中……

          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 施德明 閱讀(363) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 建昌县| 万盛区| 成都市| 睢宁县| 白河县| 万源市| 阿坝| 九龙县| 明溪县| 南木林县| 霸州市| 上杭县| 东平县| 阿拉尔市| 福海县| 台中市| 周至县| 托克逊县| 沙河市| 南岸区| 长乐市| 县级市| 新沂市| 西贡区| 大关县| 滁州市| 中西区| 清新县| 双城市| 华阴市| 萍乡市| 石家庄市| 郸城县| 修文县| 原平市| 交城县| 乳山市| 青州市| 洛南县| 新源县| 图木舒克市|