Need to set path (cp) in ant script depending on value of a property

落花浮王杯 提交于 2019-12-10 17:24:19

问题


I want to set a path variable cp to one of two values depending on the value of an property.

E.g. the following is what I'm trying to achieve, but I'm not sure about how to get it working properly...

<if>
    <contains string="${jboss.home}" substring="jboss-4.2.3.GA"></contains>
    <then>
        <echo message="Using JBoss 4.2.3 classpath"/>
        <path id="cp"> 
        ...
        </path>
    </then>
    <else>
        <echo message="Using JBoss 4.0.5 classpath"/>
        <path id="cp">
        ...
        </path>
    </else>
</if>

回答1:


<condition property="usejboss423">
    <contains string="${jboss.home}" substring="jboss-4.2.3.GA"/>
</condition>

<target name="build.jboss.cp" depends="build.jboss.cp.423,build.jboss.cp.405"/>

<target name="build.jboss.cp.423" if="usejboss423">
    <path id="cp">
    ... JBoss 4.2.3 classpath
    </path>
</target>

<target name="build.jboss.cp.405" unless="usejboss423">
    <path id="cp">
    ... JBoss 4.0.5 classpath
    </path>
</target>



回答2:


If you need to do this kind of thing a lot, install AntXtras. You just add a JAR file to Ant's class path, and you can do this:

<condition property="usejboss423">
  <contains string="${jboss.home}" substring="jboss-4.2.3.GA"/>
</condition>

<do if="usejboss423">
  ...
</do>

<do unless="usejboss423">
  ...
</do>

It has a lot of other useful features.



来源:https://stackoverflow.com/questions/666718/need-to-set-path-cp-in-ant-script-depending-on-value-of-a-property

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!