The java life

          My working life with java
          隨筆 - 7, 文章 - 0, 評(píng)論 - 2, 引用 - 0

          導(dǎo)航

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          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)航:
           
          主站蜘蛛池模板: 高邑县| 宁蒗| 娄烦县| 昌图县| 杭州市| 伊金霍洛旗| 襄樊市| 中超| 台中县| 嘉善县| 德昌县| 美姑县| 清水河县| 文安县| 灵石县| 顺平县| 专栏| 美姑县| 类乌齐县| 盐亭县| 长沙县| 莱芜市| 汽车| 毕节市| 桦川县| 泸定县| 淳安县| 雷山县| 扬州市| 万州区| 报价| 南平市| 巴塘县| 木里| 晋江市| 张家界市| 德钦县| 澳门| 广州市| 淮安市| 株洲县|