I have a Build.xml file. By using that file, I want to run another build.xml file which is in another location by using ant. How can I achieve this...?
-
2From your main xml file if you import your another xml file, then you can call desired targets directly in dependency chains : `
` – Feb 17 '14 at 14:10 -
http://stackoverflow.com/a/25207678/1422630, thru depends="" we can chose the other xml target – Aquarius Power Apr 30 '17 at 18:13
2 Answers
In brief you have two options.
You can include/import the other ant file, so you can depend on the targets or call its macros. This method kind of merges the other build file. This is more efficient if you call a lot of targets, since the file is only loaded once. Check this answer for more info on the difference between import
and include
, and check the official documentation for more details (import, include).
Another way is to execute the other ant file in a new process, using the ant
task.
In this way you can achieve higher isolation between the two build files, but the other file will be loaded once for every call.
You are also able to use antcall
when importing/including the file. You will however typically like to avoid this, since it creates a new project instance the same way ant
does. There is more on the difference between using depends
and antcall
in this great post.
Good Luck
-
1antcall doesn't call another ant file - from ant manual (https://ant.apache.org/manual/Tasks/antcall.html) : "Call another target within the same buildfile optionally specifying some properties". It's the deprecated way for reusing functionality before Ant 1.6 (released in 2003) introduced macrodef. – Rebse Feb 17 '14 at 22:03
-
subant to the rescue.
The following are examples of it's use:

- 1
- 1

- 76,015
- 10
- 139
- 185