13
votes

How to specify base dir then we run ant like ant -f somedir/dir/build.xml. Ant sets basedir relative to build.xml, if I specify

<project basedir="." ..>

I would like to have basedir pointed to place where Ant is executed.

4
can you copy build.xml to another directory?Jakob Weisblat
yes, but I'd prefer do not copy this fileAndrei N
link or symlink it then?Jakob Weisblat
I would like do not write additional commands in scripts. I'd like to modify build.xmlAndrei N
I have absolutely no idea then. sorry :)Jakob Weisblat

4 Answers

20
votes

Use -D to override the basedir property:

ant -Dbasedir=`pwd` -f path/to/build.xml

The use of pwd is a Linux-only thing, but you can always put the absolute path of the current directory there if you're on another platform.

I don't think there's a way to do this inside build.xml, short of re-executing ant with the ant task.

9
votes

You can try to use subant task:

Assuming you have two different folders

  1. Your current folder X:/your/launching/folder where you are executing ant command from

  2. Folder where your destination bulid.xml is: Y:/any/folder/with/build.xml

You can do the following:

Create build.xml in X:/your/launching/folder with the next content:

<target name="mytarget">
    <subant target="debug">
        <fileset dir="Y:/any/folder/with" includes="build.xml"/>
    </subant>
</target>

Then you can execute ant mytarget from X:/your/launching/folder folder to start building your Y:/any/folder/with/build.xml

Update:

You can override basedir property for subant build like this:

    <subant target="debug">
        <property name="basedir" value="./any/dir/with/project"/>
        <fileset dir="Y:/any/folder/with" includes="build.xml"/>
    </subant>
1
votes

another solution (if it makes more sense in some cases) could be to override basedir via the var task from the antcontrib extension as described here: https://stackoverflow.com/a/25786329/1915920

0
votes

I found, that using following solution is the easiest.

pushd somedir/dir && ant && popd

Although is seems to be to easy - it works.