Usage of Ant
What is Apache Ant
Apache Ant is a java-based software build tool (build tool). In theory, it is somewhat similar to the C/C++ make tool
Overview
ant is a tool that automates software compilation, testing, deployment and other steps. It is mostly used in Java environments. software development. In actual software development, there are many places where ant can be used.
Development environment:
System: Windows
JDK: 1.6+
IDE: eclipse
ant: 1.9.1
##Advantages
ant is a sub-project in the JAKARTA directory of the Apache Software Foundation. It has the following advantages:
1. Cross-platform Performance: Ant is written in pure Java language, so it has good cross-platform performance.
2. Simple operation: Ant is composed of a built-in task and optional tasks. Using ant tasks is like writing a command line in DOS. Ant requires an XML file (build file) when running. Ant can execute various tasks by calling the target tree. Each task implements a specific interface object.
3. Simple maintenance, good readability, and simple integration: Since Ant build files are in XML format, they are easy to maintain and write, and the structure is very clear. Ant can be integrated into the development environment. Due to Ant's cross-platform nature and simple operation, it is easy to integrate into some development environments.
Why use ant?
Among make, gnumake, nmake, jam or other existing build tools, why do we need to develop this ant tool separately?
Because these previous build tools have limitations, the original author of Ant Intolerable when developing software across multiple platforms.
- The make tool is essentially shell-based: make will evaluate some system dependencies before executing the command. This means you can easily extend these build tools using or writing any program for the operating system you're working on. However, this also means you're limiting yourself to an operating system, or at least a Unix-like type of operating system.
- The makefile tool itself is also very annoying. Anyone who has ever worked with a makefile will encounter the troublesome tab problem. "Because I added a space in front of the tab, my command line always didn't work." The original author of Ant said it too many times. Tools like Jam handle this to a large extent, but there are still some formats to use and remember.
And Ant is different. Ant uses Java class extensions instead of using shell command-based extensions. Unlike writing shell commands, configuration files are based on xml and call a target tree to perform various tasks. Each task is run by a Java object that implements a specific task interface.
Ant removes the functionality of some shell commands (such as
find . -name foo -exec rm {}), but it provides similar functionality, a cross-platform (work anywhere and everywhere) capability . If you really need to execute these shell commands, Ant has an
task that allows executing different commands depending on the operating system being executed.
To put it bluntly, the Ant tool is to solve cross-platform problems.
Using Apache Ant
Write a simple build file
The Apache Ant build file is written in build.xml.
Each build file contains a project and at least one default target. Goals contain tasks.
Projects A
project contains the following 3 attributes
Attributes | Description |
name | Project name |
default | is not The default target to use when supplying the target |
basedir | The base directory where all path calculations are done. This attribute may be overridden by the preset "basedir" attribute. If neither this property nor the property value is set, the directory path where the build file build.xml is located will be used.
|
Optionally, a description of the item may be provided by a top-level <description>
element.
Each project defines one or more goals. A goal is a set of tasks you want to perform. When you start Ant, you can select the target to execute. When there is no target, the project's default value is used.
Targets
A target can depend on another target using the depends attribute.
For example, you might have a target for compilation, and a target for release. When you execute the release target you have to execute the compile target first, so the release target depends on the compile target. It should be noted that Ant's depends attribute, if the target it depends on is not executed, but directly executes the current target, it will automatically execute the dependent target.
Tasks
A task is a piece of code that can be executed. A task can have multiple properties (or parameters, if you prefer).
The value of an attribute may contain a reference to the attribute. These references will be resolved before the task is executed.
Tasks have a common structure:
<name attribute1="value1" attribute2="value2" ... />
name is the name of the task, attributeN is the attribute name, and valueN is the value of the attribute.
All tasks share a task name attribute. The value of this property will be used for log messages generated by Ant.
Properties
Reference
- ##Apache Ant Introduction
- Hello World with Apache Ant
The above is the detailed content of Getting started with Ant. For more information, please follow other related articles on the PHP Chinese website!