Tutorials Navigation
Apache Ant Tutorial - Build Files
Tutorial Name: Apache Ant Tutorial - Build Files
Category: PC Tutorials
Submitted By: hoot
Date Added:
Comments: 0
Views: 370
Related Forum: PC Building Forum
Share:
Typically, Ant's build file, called build.xml should reside in the base directory of the project. However there is no restriction on the file name or its location. You are free to use other file names or save the build file in some other location.
For this exercise, create a file called build.xml anywhere in your computer with the following contents in it
<?xml version = "1.0"?>
<project name = "Hello World Project" default = "info">
<target name = "info">
<echo>Hello World - Welcome to Apache Ant!</echo>
</target>
</project>
Note that there should be no blank line(s) or whitespace(s) before the xml declaration. If you allow them, the following error message occurs while executing the ant build -
The processing instruction target matching "[xX][mM][lL]" is not allowed.
All build files require the project element and at least one target element.
The XML element project has three attributes
Sr.No.1- name
The Name of the project. (Optional)
Sr.No.2-default
The default target for the build script. A project may contain any number of targets. This attribute specifies which target should be considered as the default. (Mandatory)
Sr.No.3-basedir
The base directory (or) the root folder for the project. (Optional)
A target is a collection of tasks that you want to run as one unit. In our example, we have a simple target to provide an informational message to the user.
Targets can have dependencies on other targets. For example, a deploy target may have a dependency on the package target, the package target may have a dependency on the compile target and so forth. Dependencies are denoted using the depends attribute. For example
<target name = "deploy" depends = "package">
....
</target>
<target name = "package" depends = "clean,compile">
....
</target>
<target name = "clean" >
....
</target>
<target name = "compile" >
....
</target>
The target element has the following attributes
Sr.No.1-name
The name of the target (Required)
Sr.No.2-depends
Comma separated list of all targets that this target depends on. (Optional)
Sr.No.3-description
A short description of the target. (optional)
Sr.No.4-if
Allows the execution of a target based on the trueness of a conditional attribute. (optional)
Sr.No.5-unless
Adds the target to the dependency list of the specified Extension Point. An Extension Point is similar to a target, but it does not have any tasks. (Optional)
The echo task in the above example is a trivial task that prints a message. In our example, it prints the message Hello World.
To run the ant build file, open up command prompt and navigate to the folder where the build.xml resides, and type ant info. You could also type ant instead. Both will work, because info is the default target in the build file. You should see the following output
C:\>ant
Buildfile: C:\build.xml
info: [echo] Hello World - Welcome to Apache Ant!
BUILD SUCCESSFUL
Total time: 0 seconds
C:\>
Ratings
Comments
Related Tutorials
- 01. Emulating Xbox 360 on PC for Running COD4 With Mods(2,032)
- 02. How to: Matrix Numbers | Batch File(1,577)
- 03. How to Password Protect Files on Windows(761)
- 04. How to play Socom 2/3/ and Combined Assault on PC(5,103)
- 05. Modern Warfare 2 Vac Ban Bypass Tutorial(5,001)
- 06. How to embed an image on TheTechGame(2,763)
- 07. [PC] NIOH 2 OTHER USER SAVE RESIGN(12,287)
- 08. Host bot lobbies! Full Tutorial!(9,500)
- 09. Unban yourself [Plutonium BO2](13,429)
- 10. Fall Guys - How to Change Your Name Color on Fall Guys(8,013)
- 11. Best Crosshair Settings for Valorant(6,153)
- 12. Othercide The Surgeon Boss Guide(2,216)
- 13. Othercide Remembrances Unlock Guide(3,905)
- 14. Othercide Beginners Tips and Tricks(2,432)
- 15. How to Fix Grounded Crashes, Loading Time, Low FPS and Other(4,344)
"Apache Ant Tutorial - Build Files" :: Login/Create an Account :: 0 comments