The java life

          My working life with java
          隨筆 - 7, 文章 - 0, 評論 - 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 施德明 閱讀(360) 評論(0)  編輯  收藏


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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 平利县| 偏关县| 荃湾区| 塘沽区| 安徽省| 渭南市| 江油市| 兴化市| 光泽县| 道真| 获嘉县| 高清| 克什克腾旗| 泰来县| 保康县| 绥棱县| 泰顺县| 芒康县| 永靖县| 扶余县| 侯马市| 且末县| 康马县| 汕头市| 九龙县| 钟祥市| 丽水市| 边坝县| 百色市| 丹阳市| 康保县| 新兴县| 顺平县| 金阳县| 滦平县| 新宁县| 梁河县| 鄯善县| 额尔古纳市| 广东省| 蒲江县|