3

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...?

user3318296
  • 31
  • 1
  • 2
  • 2
    From 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 Answers2

2

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 importand 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

Community
  • 1
  • 1
Tobber
  • 7,211
  • 8
  • 33
  • 56
  • 1
    antcall 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
  • My bad. Thanks for the correction. I'll update the answer right away. – Tobber Feb 18 '14 at 06:12
2

subant to the rescue.

The following are examples of it's use:

Community
  • 1
  • 1
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185