开发者

Ant - conditional statement

I'm using ant to build my app, and I want to have single process for dev/qa/prod versions of the app. I want to do be able to specify the build target from command line:

ant -Dbuildtarget=dev|qa|prod

and in build.xml check for the value of buildtarget and set an application specific base URL property based on the buildtarget specified by the user. I will subsequently set the correct runtime param using

    <copy file="pre.app.properties" tofile="./app.properties" overwrite="true">
        <filterset>
            <filter token="BASE_URL" value="${baseurl}" />
        </filterset>
    开发者_运维技巧</copy>

What I am stuck on is how to express this in and build.xml ?

if buildtarget=='dev' 
    baseurl="http://my_dev_url"
else if buildtarget=='qa' 
    baseurl="http://my_qa_url"
else if buildtarget=='prod' 
    baseurl="http://my_prod_url"

I've searched around, but this seems to be difficult to do in ant. Any ideas ?


When starting your ant script with ant -Dbuildtarget=dev|qa|prod it's as simple as =

<project >
  <property name="baseurl" value="http://my_${buildtarget}_url"/>
  <echo>$${baseurl} => ${baseurl}</echo>
</project>

The buildtarget property can be used as dynamic part of the baseurl property.
Afterwards ${buildurl} can be used for further processing..


Perhaps you should try using the condition task of ant?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜