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
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
I found, that using following solution is the easiest.
pushd somedir/dir && ant && popd
Although is seems to be to easy - it works.
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.
You can try to use subant task:
Assuming you have two different folders
Your current folder X:/your/launching/folder where you are executing ant command from
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>